When using System.Timers.Timer, use the SynchronizingObject Timer Property. Apparently, this calls a method that processes the Elapsed event to be called in the same thread in which the assigned component (SynchronizingObject) was created. eg. if myButton is a control of your form (regardless of the main GUI thread),
System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.SynchronizingObject = this.myButton;
this leads to the fact that the Elapsed handler runs in the same thread, removes errors "cross-thread operation".
Pls note: I have very little information about whether this is thread safe, but works fine for me in a specific use case. Hope it helps anyway.
source share