I have a C # .NET console application that sends an email using SmtpClient .
The following behavior appears in the code below:
- Set a break point somewhere above line 35
- Click the break point, go to lines 30, 32, etc.
- Before he hits line 35, he will return to line 28 again
- At some point, I get a "Process or thread has changed from the last step" message
- Jumping seems random

Why is my break point jumping?
what does this message mean?
Is there something wrong with my code?
( https://stackoverflow.com/questions/958705/... Probably the same, but this is ASP.NET)
The following is the Pass Hans pointer.
This version still allows race status: the Toggle Timer.AutoReset property in my timer event handler to avoid re -entrancy while the code is running.
private void OnTimerElapsed(object source, ElapsedEventArgs e) { timer.AutoReset = false;
Final version: Initialize the timer with AutoReset already set to false, and then call Timer.Start() again at the end of the Elapsed event handler.
public void Start() { timer = new Timer(checkInterval); timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed); timer.AutoReset = false; // prevent race condition timer.Start(); } private void OnTimerElapsed(object source, ElapsedEventArgs e) { bool exceptionIsNasty = false; try { MyClass.SendMail(smtpServer, account, password); // do stuff } catch (Exception ex) { // Log exception, set exceptionIsNasty to true if the mailing should be stopped //... } finally { if (!exceptionIsNasty) timer.Start(); // allow another Elapsed event } }
Johnb source share