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)
Share with