How do I schedule events for execution ?

  • Thread starter Thread starter pamelafluente
  • Start date Start date
I have previously looked into this a bit, and came up with something along
the lines of the following (I've read the rest of the thread up to this
point, and you still seem stuck on the idea of a loop and/or lots of
threads. I don't know how your tasks are stored, but have you thought about:

Upon initialisation and/or startup and/or addition/change to the list of
tasks:
Cancel current timer if not startup.
Re-order tasks by next run time.
Do tick code.

Do tick code:
Check for tasks that should already have run (now > next run time) and run
them if necessary - i.e. if there's been a power failure.
Update the next run time for the task, and insert it into the list in
the correct location (i.e. so you don't mess up the ordering).
Find the task with the next soonest run time and set a timer to run once and
fire at that time which calls Do tick code.


You will need to check what happens if you set a timer with a negative
value - this could happen with tasks that are sheduled to start very close
together - you'd check for tasks that should have run, find the next time,
and by the time the timer has been set up, that time has already passed. In
this instance, the program might never fire the tick code again, and
effectively stall.

With this way, you only need to loop through as many tasks that should have
already run but haven't yet - you stop when you get to the first task with a
"next run time" > now.

Does that make sense? This was written very quickly, so might have a mistake
or two :)

Jevon
 
Must say that I didn't think about such a way of using the timer. I
like it very much. It's somehow a solution in between what we have
discussing so far. Seems an efficient one...

Leave the word to the others...

-Pam
 
As what you, Cor, suggest, I am not clear on the reason to call a sub
main. Wouldn't be a new thread just the same thing?
Splits your program, one is the scheduler and one is the one which is doing
the jobs.

What they have to do is what activity is scheduled, you can pass that, which
is accepted by using a sub main and not the normal initializing from a
mainform (with inbuild sub main) as is standard done in VBNet.

By that you create seperate programs which run on their own threads (as long
as you allow multiple programs with the same name active, what is standard).

Timers are not starting a new threads. (Although some timers run on their
own thread).

I hope this helps,

Cor
 
Thank you very much to all.

You have been really helpful with this matter.

I am gonna to assemble my solution taking the best from all of your
generous suggestions !!!

THANKS!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top