Sky Software Homepage LogicNP Software Knowledge Base And FAQ

 
Contact Product Support    SearchSearch      Subscribe to the RSS feed for this forum

HOWTO : Create a new task using Taskscheduler component.

 
Subscribe to the RSS feed for this forum  Forum Index -> ShellObjects.Net/WPF
View previous topic :: View next topic  
Author Message
Support



Joined: 18 Jul 2005
Posts: 731

Posted: Fri Apr 11, 2008 11:46 am    Post subject: HOWTO : Create a new task using Taskscheduler component.

When you create a new task, the first thing you have do is to set the application path and the account information of the task and then save the task. Always save and close the task to apply these settings. Then reopen it to schedule it.
The following code demonstrates the steps.

[C#]

Task t = taskScheduler1.CreateTask( "TaskName" );
t.ApplicationName = "Application"; //Set the full path of the application
bool RunOnlyIfLoggedOnFlag = false; //If you want to run the task under currently logged on account then set RunOnlyIfLoggedOn to true
//You can later set the other flags
if (RunOnlyIfLoggedOnFlag)
{
t.Flags = TaskFlags.RunOnlyIfLoggedOn;
t.SetAccountInformation("AccountName", null); //Specify only user account and null for the Password
}
else
{
t.SetAccountInformation("AccountName", "Password"); //Specify the user account and the Password
}
t.Save(); //Save the task and close
t.Close();

t = taskScheduler1.OpenTask( "TaskName" ); //Reopen the task
DateTime dt= DateTime.Now.AddMinutes(1); //Schedule the task
Trigger tr = new DailyTrigger(dt);
tr.EndDate = DateTime.Now.AddDays(3);
t.Triggers.Add(tr);
t.Save(); // Always save and close the task to save your changes
t.Close();


[VB]

Dim t As Task = TaskScheduler1.CreateTask( "TaskName" )
t.ApplicationName = "Application" 'Set the full path of the application
Dim RunOnlyIfLoggedOnFlag As Boolean = False 'If you want to run the task under currently logged on account then set RunOnlyIfLoggedOn to true
'You can later set the other flags
If (RunOnlyIfLoggedOnFlag) Then
t.Flags = TaskFlags.RunOnlyIfLoggedOn
t.SetAccountInformation("AccountName", Nothing) 'Specify only user account and null for the Password
Else
t.SetAccountInformation("AccountName", "Password") 'Specify the user account and the Password
End If
t.Save() 'Save the task
t.Close() 'Close it

t = TaskScheduler1.OpenTask( "TaskName" ) 'Reopen the task
Dim dt As DateTime = DateTime.Now.AddMinutes(1) 'Schedule the task
Dim tr As Trigger = New DailyTrigger(dt)
tr.EndDate = DateTime.Now.AddDays(3)
t.Triggers.Add(tr)
t.Save() ' Always save and close the task to save your changes
t.Close()
Back to top
Display posts from previous:   
Forum Index -> ShellObjects.Net/WPF All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group