By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

threading problem again

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"dzemo" <dz***@wizard.ba> schrieb
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

Nov 21 '05 #2

P: n/a
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.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.