I have a MainForm
and method which opens new window:
private void OpenWindow(object source, ElapsedEventArgs e)
{
var form = new SomeForm();
form.MdiParent = this;
form.Show();
}
And timer:
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += new ElapsedEventHandler(OpenWindow);
timer.Interval = 10000;
timer.Enabled = true;
And it throws error on setting MdiParent
: form.MdiParent = this;
Cross-thread operation not valid: Control 'MainForm' accessed from a thread other than the thread it was created on.
How can I solve this problem?