How to stop timer while debugging

If you want you can wrap this into a #if DEBUG directive or you can use System.Diagnostics.Debugger.IsAttached.


In your Timer.Elapsed event handler, maybe you can use some preprocessor directives to include code that stops and starts (or disables and enables) the timer:

    private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {
#if DEBUG
        (source as Timer).Stop();
        // or
        (source as Timer).Enabled = false;
#endif

        // do your work

#if DEBUG
        (source as Timer).Start();
        // or
        (source as Timer).Enabled = true;
#endif
    }