I have a System.Timers.Timer that randomly throws a NullReferenceException when I call the Stop() method. This probably occurs probably about 4 times a work day. I’ve seen the problem repeated on multiple computers.
void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (myTimer != null) //trying to stop the exception here
{
myTimer.Stop(); //Null Reference Exception occurs here
DoStuff();
myTimer.Start();
}
}
The stack looks like this:

The weirdest part is that I can immediately start the program again from the position of the exception with no problems.
Try this