Reputation: 17121
The short form of this question: When, if ever, is it appropriate to use the Forms.Timer in a multithreaded WinForms application?
More specifically, I am architecting an application that uses multiple System.Threading.Timers to launch processes asynchronously, check queues containing the results of those asynchronous processes, and update the statistics to be shown by the application's main form.
In an application like that, is it appropriate to use a Forms.Timer to actually check the application statistics and draw them to the main form or would that just throw a wrench into the application's smooth running?
Upvotes: 21
Views: 10239
Reputation: 61223
I agree with what Mehrdad and David said, but you should be aware that timers offer no guarantee of timeliness or order or execution. Too many timers and the application will just hang ;-)
Upvotes: 2
Reputation: 421968
Forms.Timer
registers the timer to send a message when the timer goes off. The event raised is treated like a GUI event. System.Threading.Timer
uses a thread blocking approach. Basically, you should use Forms.Timer
for your GUI oriented timers (to add some effects to the user interface) and Threading.Timer
for scheduling tasks and other things.
Upvotes: 26