This project has moved. For the latest updates, please go here.

I want to create a schedule that will run every 1 hour in a day.

Topics: Setup
Feb 14, 2013 at 7:26 AM
Hi,

I want to create a schedule that will run every 1 hour in a day, but I am not able to figure out how to do that.

Thanks,
-Prashant
Coordinator
Feb 14, 2013 at 10:54 PM
Edited Feb 14, 2013 at 10:55 PM
Assuming the task begins triggering immediately, runs indefinitely and executes a program:
DailyTrigger dt = new DailyTrigger();
dt.Repetition.Duration = TimeSpan.FromHours(23);
dt.Repetition.Interval = TimeSpan.FromHours(1);
new TaskService().AddTask(taskName, dt, new ExecAction("notepad.exe", "c:\\test.log", null));
Marked as answer by dahall on 9/1/2015 at 10:10 AM
Feb 18, 2013 at 8:15 PM
Thanks, It worked.

I have another query. In task scheduler General Tab - I want to select radio button "Run weather user is logged on or not".
I am getting error by trying following code:

CODE:
TaskDefinition td = ts.NewTask();
td.Settings.RunOnlyIfLoggedOn = false;
ERROR:
NotV2SupportedException' was unhandled. An unhandled exception of type 'Microsoft.Win32.TaskScheduler.NotV2SupportedException' occurred in          Microsoft.Win32.TaskScheduler.dll
Coordinator
Feb 19, 2013 at 1:04 AM
Yes. That setting is reserved for systems after XP. You must be on an XP or Server 2003 system.
Feb 19, 2013 at 1:34 AM
No, I am trying to run the program on Win 8 operating system.
Coordinator
Feb 19, 2013 at 4:04 PM
Edited Feb 19, 2013 at 4:05 PM
I was incorrect. That setting only works on XP and earlier. To do what you want on Vista and later, int the RegisterTaskDefinition method you need to supply a password and use the TaskLogonType.Password or InteractiveTokenOrPassword or you will need to use a service account (like System or Local Service) and the TaskLogonType.ServiceAccount or you can supply a normal account, use the TaskLogonType.S4U, and not access either the network or encrypted files.
Jan 27, 2014 at 1:42 AM
Hi,
I upgraded to latest released dll in my project.
When I am trying to run below code on Win 8.1 OS it's giving error on below bold line:

Code:
TaskDefinition td = ts.NewTask();
td.Settings.RunOnlyIfLoggedOn = true;

Error:
NotV2SupportedException' was unhandled. An unhandled exception of type 'Microsoft.Win32.TaskScheduler.NotV2SupportedException' occurred in Microsoft.Win32.TaskScheduler.dll

The error is coming before registering the task and I am passing the password and task logon type while registering only.
ts.RootFolder.RegisterTaskDefinition(scheduleName.Text, td, TaskCreation.CreateOrUpdate, domainName + "\" + userName, password, TaskLogonType.Password, null);

Is there any workaround/example which I can refer to set "RunOnlyIfLoggedOn" property.
Coordinator
Jan 27, 2014 at 3:35 PM
Please check previous posts before asking questions. This has actually been answered in two other posts. Read my response in https://taskscheduler.codeplex.com/discussions/84859.
Marked as answer by dahall on 9/1/2015 at 10:10 AM
Jan 28, 2014 at 4:24 PM
Thanks It worked.
Jan 31, 2014 at 12:43 AM
My task is created successfully at the defined time using daily trigger. The first time it will execute will be as per schedule but,
I want to start the execution of task immediately once its created and from next time it should run as per schedule.

Is there any way to do that?
Coordinator
Feb 1, 2014 at 7:08 PM
Look at the Repetition properties under the trigger. These (Interval and Duration) will let you start at the time the trigger specifies and then repeat at a specified interval for the length of a specific duration.
Marked as answer by dahall on 9/1/2015 at 10:10 AM
Feb 14, 2014 at 9:29 AM