try { using (TaskService ts = new TaskService()) { // Create a new task definition and assign properties TaskDefinition td = ts.NewTask(); td.RegistrationInfo.Description = "working with network failOver"; td.Principal.LogonType = TaskLogonType.InteractiveToken; // Add a trigger that will fire the task at this time every other day DailyTrigger dt = (DailyTrigger)td.Triggers.Add(new DailyTrigger(24)); dt.Repetition.Duration = TimeSpan.FromMinutes(5); dt.Repetition.Interval = TimeSpan.FromMinutes(2); // Add a trigger that will fire every week on FridayDaysOfTheWeek.Friday td.Triggers.Add(new WeeklyTrigger(DaysOfTheWeek.AllDays, 1));// + TimeSpan.FromHours(2), DaysOfWeek = DaysOfTheWeek.Friday }); td.Actions.Add(new ExecAction(AppDomain.CurrentDomain.BaseDirectory + @"Data.aspx\shedularEXE\HandlingConnFailover", "c:\\test.log", null)); // Register the task in the root folder const string taskName = "Sync All Database"; ts.RootFolder.RegisterTaskDefinition(taskName, td); // Retrieve the task, change the trigger and re-register it Task t = ts.GetTask(taskName); td = t.Definition; td.Triggers[0].StartBoundary = DateTime.Now.AddMinutes(2);//.Today;//+ TimeSpan.FromDays(7); ts.RootFolder.RegisterTaskDefinition(taskName, td); // Remove the task we just created // ts.RootFolder.DeleteTask(taskName); } } catch (Exception ee) { string s = ee.Message; }
ts.RootFolder.RegisterTaskDefinition(taskName, td)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)