Click here to Skip to main content
16,005,178 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My application displays rows in a listbox, which contains code that controls a physical device via USB. I want to have a processing time between the lines. Such as when the first row is processed, the second should be processed only after 1 second, and so on.
How can I do this? Thanks in advance.
Posted

1 solution

Use a separate thread for this purpose and dynamically calculate sleep time between the lines asking the current time using System.DateTime.Now, calculate how much time to sleep and use System.Threading.Thread.Sleep.

Alternatively, use (sigh…) a timer. Timer seems easier to use, but in fact it's harder to use it reliably. There are three timers in .NET:

System.Threading.Timer; see http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx[^];

System.Timers.Timer; see http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx[^];

System.Windows.Forms.Timer; see http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx[^]; avoid using this one by all means: it is very inaccurate even though it's easier to use.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900