We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback
Platform : WinForms
|
Category : Tips

What are the implications of using the Timer class in System.Timers as opposed to the Timer class in System.Windows.Forms

Be careful when using the Timer from System.Timers from within a Windows.Form application. Most methods in Windows Forms are not thread safe and can produce indeterminate results when called from another thread. In this case, System.Timers.Timer is much higher resolution and less affected by how busy your application is (since it doesn’t use the message pump) but it’s Tick event is fired from another thread. In order to be sure this works correctly, you’ll have to write the proper Control.Invoke code to marshal over to the thread the control was created on (the main thread) before you call methods on the control. So, in cases where you don’t need super-high-resolution and regular events to be fired, you’re much better off using System.Windows.Forms.Timer. It’s message pump is based (WM_TIMER) and will fire on the UI thread.

(from sburke_online@microsoft..nospam..com on microsoft.public.dotnet.framework.windowsforms)

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon