First of all, tasks do not have to have any triggers so unless you know there is at least one trigger, you should check Triggers.Count > 0 before getting the indexed trigger.
To answer your question, I believe you are looking for the following:
To answer your question, I believe you are looking for the following:
Dim delayTime As TimeSpan
Using taskServiceObject As TaskService = New TaskService()
Dim taskObject As Microsoft.Win32.TaskScheduler.Task = taskServiceObject.GetTask("mytask")
' Makes sure that the task exists and we don't get a Null Reference Exception.
If (taskObject IsNot Nothing) And (taskObject.Definition.Triggers.Count > 0) Then
Dim trigger As Trigger = taskObject.Definition.Triggers.Item(0)
If (trigger.TriggerType = TaskTriggerType.Logon) And (TypeOf trigger Is ITriggerDelay) Then
' Get Delay Time Here and store it in a variable
delayTime = CType(trigger, ITriggerDelay).Delay
End If
End If
End Using
Technically, you don't need to check if the trigger type is Logon unless your code requires it. If you need seconds or milliseconds from the TimeSpan object, there are methods and properties on that object to extract that details.