I have a win form that is using a System.Timers.Timer. When the timer executes it updates a variable on the mainForm. I am getting an exception telling me that mainForm has been disposed. What am I doing wrong. If I take out updating the variable the program runs fine. If I try and read the variable and post it to a message box, everything works fine. Only when I try and change the value of the variable from the timer event handler do I get the exception. What is going on?
//works
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
MessageBox.Show(myVarFromMainForm);
}
//does not work
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
myVariableFromMainForm = 10;
}