Help: Threading a timer

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

How do I put a timer in it's own thread? The reason I need this is that I
may have like 30 timers going continuously and it's more efficient (right??)

Thanks.
 
Hi VB programmer

Take a look at "system.timers.timer"

I thought that has already itself his own thread.

And don't use forms.form.timer, that you can drag from the desinger,

Just and advice

Cor
 
How do I "attach" code to the timer, adjust interval properties, etc... if I
use "system.timers.timer"?
 
Hi VBP, Cor,

Actually there are <three> sets of Timers.

Forms.Timer is the familiar drag-n-drop one.

System.Timers.Timer is one that can be used without a Form. It's
similar in use in that it raises an Event to which a class in your app
subscribes.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/fr
lrfsystemtimerstimerclassctortopic.asp

System.Threading.Timer is one which you provide a callback method.
When the Timer goes off, this method is called in its own Thread.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/fr
lrfsystemthreadingtimerclassctortopic2.asp

Ok, that's the choices. There's a (typically MSDN) example with each.

Is it more efficient? First some questions: ;-)

What are they for?
How often will they go off?
Same interval for each?
Staggered or all at once?
What jobs will get done?
How long will the jobs take?

Regards,
Fergus
 
Ho Cor,

Lol. More? Excellent - can't have too few Timers. ;-)

What did I miss?

Regards,
Fergus
 
Hi Fergus,

I was helping someone together with OHM and then suddenly I saw a timer I
never had seen. It was something like the Strconv function. It exist but if
you haven't seen it and you won't believe that such a simple and small
function exist.

But this timer had no advantages, so I forgot it, I only did remember that
there was another one (I hope it was not a bad dream). I did not found it
again now by searching and I find it is to unimportant, the three you
mentioned where the most important I think.

But there are more timers, this I did find in a search in
"time-to-reach-queue timer".

I was busy a while with those timers, the problem is that espacialy the form
and the stystem timer workint totaly different so in the documentation you
have to watch very carefully what you are using.

And now I use automaticly the thread.sleep, that is easy to manage and with
an do application.event you can do everything with it even in threads, but
of course very inaccurate.
(When I tell it how I use it I get standard a message from Herfried).

But that is of course not good answer to an OP who ask for a timer.

:-)
Cor
 
Hi Cor,

Thanks. If that function does turn up.. well, I'm curious now. ;-)

~~ I hope it was not a bad dream

I've been dreaming all morning (before I was fully awake) that a pizza and
ingredients that I got ready lat night were missing. As the dream was mixed up
with languages.vb thoughts, it was very strange. The pizza's still three
though. Maybe it's an important post that's missing.

I believe that the Timers use Sleep themselves. The Forms one has a
resolution of 55ms which is adequate for UI work. I'm not sure of the
Timers.Timer one. The Threading one is 1ms, as is Sleep itself. [There was a
query in vb.winapi from a guy who couldn't get his below 10ms. Something about
not setting it right - but that was WinApi not .NET]

Using Thread.Sleep is perfecty valid - as you say it's very
straightforward - and may be a better solution than using Timers so I'd put
the idea forward - let the OP decide. ;-)

Cheers,
Fergus
 
Back
Top