I love the scheduler class bt how do i schedule a atask by date\time instead of milliseconds?
You could just figure out the milliseconds using timespan and send that in, (or you could keep reading below)
// first find out what time it is now DateTime current_dt = DateTime.Now; // second create some time in the future you'd like to execute DateTime when_you_want_to_execute = DateTime.Now.AddMinutes(30); // Use timespan to find the difference between the two date time objects TimeSpan timespan = when_you_want_to_execute - current_dt; // divide the total ticks of the timespan by how many ticks per millisecond // to get how many milliseconds should lapse between now and then // and then you can just send in how many milliseconds before you want to execute long millisecond_difference = timespan.Ticks / TimeSpan.TicksPerMillisecond; scheduler.ScheduleTask(millisecond_difference, ledOn, ExecutionEventMode.DontInformJustExecute); //turn the light on
That being said, I just threw in two more methods, and I'll update the solution up top there. Just be wary, that DateTime is relative. So if you set up some datetime 3 second in the future, but you don't schedule it for 5 seconds, you will be trying to schedule it in -2 seconds. If I see a negative number I change it to 0, and it will be executed immediately. Best of luck
//Schedule an event using a datetime object DateTime when_you_want_to_execute = DateTime.Now.AddSeconds(5); //Some DateTime in the future scheduler.ScheduleTask(when_you_want_to_execute, new DebugAction("Try out Date Time."), ExecutionEventMode.DontInformJustExecute);