

Netduino scheduler
#1
Posted 15 August 2010 - 07:14 AM

- i182willsw likes this
#2
Posted 15 August 2010 - 07:24 AM

#3
Posted 15 August 2010 - 03:13 PM
That's a nice scheduler framework. Wow. Didn't you just get your Netduino?
One thing I should bring up...It's perfectly fine to run your code in loop on a Netduino, but .NET Micro Framework is designed to go into "low power" mode when all threads are asleep. So if you put together a scheduler that called Thread.Sleep(##ms) between scheduled events, you'd have a battery-friendly scheduler.
As we work on the power management code in future Netduino firmware releases, this will become more and more beneficial. [Of course, you couldn't do an input in a sleeping scheduler--but as you noted in your code that's not the best way to do it anyway; an InterruptPort would be the best option there...]
Chris
Friday afternoon. That does bring up the question I keep meaning to ask. Could you expound a bit on the netduino's event driven architecture? Is there a specific amount of threads running? Are they doing certain tasks? There aren't mutexes in the .net micro architecture, but I do see we have the ability to lock a code block. Time to go rewrite the scheduler and make it thread safe. That's pretty cool that it has a LPM.
#4
Posted 15 August 2010 - 04:17 PM
Friday afternoon. That does bring up the question I keep meaning to ask. Could you expound a bit on the netduino's event driven architecture? Is there a specific amount of threads running? Are they doing certain tasks? There aren't mutexes in the .net micro architecture, but I do see we have the ability to lock a code block. Time to go rewrite the scheduler and make it thread safe. That's pretty cool that it has a LPM.
.NET Micro Framework is a cooperatively-multitasked runtime and the threads are virtual. The threads are very lightweight, so creating a few won't hurt anything. Just be sure to do very small tasks on your threads if you have time-sensitive code in your project (as cooperative multitasking allows up to 20ms timeslices max per thread).
Chris
#5
Posted 15 August 2010 - 06:05 PM
#6
Posted 16 August 2010 - 03:14 AM


#7
Posted 16 August 2010 - 04:06 AM
#8
Posted 16 August 2010 - 04:40 AM

#9
Posted 16 August 2010 - 05:15 AM
Thanks, I do love your code action scheduler. I would have never thought of doing something like that.Very possible, I was actually just giving examples of actions
It's all about time, if you've got time to make some really souped up stuff I'm all bout it.
#10
Posted 16 December 2012 - 01:10 PM
tony
#11
Posted 16 December 2012 - 06:06 PM
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);
#12
Posted 28 January 2014 - 05:54 AM
it's cool... hmm how if you want to callback action daily at 00:05 AM?
i just wonder to use
system.thread.timertimer _timer = new timer(callbackAction, Timespan.Zero, new Timespan(1,0,5,0));
but then I realize that, If i start this code on 3pm, then it will execute every 3pm instead 00:05 Am....
very appreciate any solution.
cheers
#13
Posted 28 January 2014 - 11:55 PM
I have some code to accomplish this at home. I'll share it either tonight or tomorrow night.
#14
Posted 29 January 2014 - 09:44 AM
Hi Giuliano de medicci...
share me please... hihi ... now I'm using standard loop by using RTC
int currentday = 0;int today = datetime.day;while (true){if (today != currentday) // for daily action{ action;}currentday == today;if (datetime.minutes %10 > 0) //this for 10 minutes schdule.no worries to rplace it by using timer/timespan{ recordData;}else{ postData; // this action takes about 10 - 15 secs. so I waste the rest of minutes = 10}}
so it will execute the action every day at the change of the day.
but if there's another way to using timer and timespan, i would love it... bcoz I've using so many "if else" on the loop...
cheers
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users