简体   繁体   中英

Using task scheduler for scheduling job in C#

i am using following code for scheduling task in c#

  TaskDefinition td = ts.NewTask();
        DateTime t = ts.RootFolder.Tasks["Test"].LastRunTime;
        td.RegistrationInfo.Description = "Does something";

        td.Triggers.Add(new TimeTrigger(DateTime.Now + TimeSpan.FromSeconds(10)));
        //td.StartBoundary = DateTime.Today + TimeSpan.FromHours(23);

        td.Triggers.Add(new WeeklyTrigger
        {
            StartBoundary = DateTime.Today + TimeSpan.FromHours(2),
            DaysOfWeek = DaysOfTheWeek.Friday
        });

i want to add week days more than one...

I found that i can do this by using

DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Tuesday | DaysOfTheWeek.Wednesday
         | DaysOfTheWeek.Thursday | DaysOfTheWeek.Friday | DaysOfTheWeek.Saturday

But the problem is that i want to do this dynamically. User will choose on week days and then i will set... pls help how to do this.

You can keep a list of integer with user selections

Then you could do

foreach (int day in days) 
{
    td.DaysOfWeek |= (DaysOfTheWeek)day;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM