I'm trying to use System.Timers.Timer on a UI control.
The error: System.Timers.Timer "Cross-thread operation not valid: Control 'txtOutput' accessed from a thread other than the thread it was created on."
My code is the following:
System.Timers.Timer timeRandomEvent = new System.Timers.Timer(10 * 1000);
// timer for random events
timeRandomEvent.Elapsed += new ElapsedEventHandler(timeRandomEvent_Elapsed);
timeRandomEvent.Start();
void timeRandomEvent_Elapsed(object sender, ElapsedEventArgs e)
{
wl("Adding some text to a text box."); // Exception occurs here
}
Is there a way to allow it, or another alternative that's hopefully easy?