In this example we will create two linked tasks:
Let's create a summary task first:
[C#]
Task task1 = file.AddTask();
task1.Name = "Summary Task";
[Visual Basic]
Dim task1 As Task = file.AddTask()
task1.Name = "Summary Task"
And now two subtasks:
[C#]
Task task2 = task1.AddTask();
task2.Name = "First Sub Task";
task2.Duration = new Duration(10, TimeUnit.Days);
task2.Start = new System.DateTime(2003, 1, 1);
Task task3 = task1.AddTask();
task3.Name = "Second Sub Task";
task3.Duration = new Duration(15, TimeUnit.Days);
[Visual Basic]
Dim task2 As Task = task1.AddTask()
task2.Name = "First Sub Task"
task2.Duration = New Duration(10, TimeUnit.Days)
task2.Start = New System.DateTime(2003, 1, 1)
Dim task3 As Task = task1.AddTask()
task3.Name = "Second Sub Task"
task3.Duration = New Duration(15, TimeUnit.Days)
Now we'll link second subtask to start right after first:
[C#]
Relation rel1 = task3.AddPredecessor(task2);
rel1.Type = TaskLinkType.FinishToStart;
[Visual Basic]
Dim rel1 As Relation = task3.AddPredecessor(task2)
rel1.Type = TaskLinkType.FinishToStart