I have a C# Windows Form application that contains a menu with this event:
private void createMenuItem_Click(object sender, EventArgs e)
{
canvas.Layer.RemoveAllChildren();
canvas.Controls.Clear();
createDock();
}
I would like to provide the user with the opportunity to fire this event through another menu option that pulls up a timer.
My timer looks like this:
private void transfer_timer()
{
System.Timers.Timer Clock = new System.Timers.Timer();
Clock.Elapsed += new ElapsedEventHandler(createMenuItem_Click);
Clock.Interval = timer_interval;
Clock.Start();
}
When I do this the resulting error message is:
createDock - Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
What am I doing wrong?