Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

kingpin2k's Content

There have been 1 items by kingpin2k (Search limited from 29-March 23)


By content type

See this member's

Sort by                Order  

#41631 Netduino scheduler

Posted by kingpin2k on 16 December 2012 - 06:06 PM in Project Showcase

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);




home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.