threading problem again

  • Thread starter Thread starter dzemo
  • Start date Start date
D

dzemo

I want to have two thread at the same time to execute. Both of threads have
to execute some code in specific intervals for example first thread have to
read from COM port every 5 seconds and other thread have to update database
every 10 seconds (code for reading from COM and update database I have).
Haw to make threads to execute in intervals?
thx
 
dzemo said:
I want to have two thread at the same time to execute. Both of threads
have to execute some code in specific intervals for example first thread
have to read from COM port every 5 seconds and other thread have to
update database every 10 seconds (code for reading from COM and
update database I have). Haw to make threads to execute in
intervals? thx


In each thread, use System.Threading.Thread.Sleep to wait for the next time
to read from the port or update the database.

Armin
 
Why not use System.Threading.Timer to create your threads?

Then, the execution speed of the code inside each thread won't affect the
actual intervals at which are activated. Naturally, any such timing will be
only relatively accurate. That is, you have to expect some jitter. Five
seconds won't be EXACTLY five seconds and ten seconds won't be EXACTLY ten
seconds. Each may be off by a few mS each time. However, for the purpose
you describe, this should work fine.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
 

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