How to wait until remote .NET debugger attached

You can use the System.Diagnostics.Debugger.IsAttached property to check if a debugger is attached to the process. This application will wait until a debugger has been attached:

using System;
using System.Diagnostics;
using System.Threading;

namespace DebugApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Waiting for debugger to attach");
            while (!Debugger.IsAttached)
            {
                Thread.Sleep(100);
            }
            Console.WriteLine("Debugger attached");
        }
    }
}

Leave a Comment