If I create a standard C# Forms app, add a button, and inside the buttons onClick handler I put the following code:
...
{
// workerThread is a member of the form
workerThread = new Thread(new ThreadStart( DoWork ) );
workerThread.Start();
}
...
void DoWork()
{
while(true)
{
Debug.WriteLine("Hello"); // <-- put breakpoint here. It gets hit but VS hangs then thread exits. Form keeps running fine.
Thread.Sleep(50);
}
}
So long as I do not put a breakpoint in the DoWork it runs fine. If I put a breakpoint once it gets hit VS hangs for a couple of seconds then when it resumes it reports the thread has exited and the DoWork breakpoint no longer gets hit. No exceptions are thrown.
Any ideas what causes this behaviour
Thanks,
Jack

Hitting breakpoint in thread causes thread to exit
Mario.Chavez
I don't see why it shouldn't be possible, I just know it does not work. In my apps, the breakpoint will hit OK, but it will take ages for the IDE to stop, and by then, I can't interact with any variables, they have 'timed out'. And if I try to start the app again, nothing will happen.
Blair Murri
Debugging multi threaded code just plain does not work. I have a multi threaded app, and unless someone can suggest a 'debug multi threaded' setting ( and a reason why you'd ever want this to break ), I've just plain given up.
BRenfro
Heh, well im coming from a C++ background where you can debug multithreaded apps perfectly well in VS.
I'd be surprised if this wasnt possible in C#...!!