Debugging problems with multiple threads in VS 2005

R

rwaddell

I'm using Visual Studio 2005 Pro final, and I've noticed some bizarre
behaviour when I'm debugging programs with multiple threads.
Specifically, if I set a breakpoint in one of my non-UI threads, and
try to step-over a line of code, my thread aborts and pretty much
breaks my application. I tried a similar test in a console application
and it seems to work fine.

Here is a sample to show what I mean. Create a new Windows application
called WindowsApplication1, and replace form1.cs with this code:

=== begin source code ===

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Thread newThread = new Thread(new ThreadStart(_runThread));
newThread.Start();
}

private void _runThread()
{
File.AppendAllText(".\\tempfile.txt", "this is a line of text\n");
}
}
}

=== end source code ===

put a breakpoint in _runThread, and run the application. What it is
SUPPOSED to do, is display the app and just put that line of text into
a text file (run the app normally, and you see that it does). But if
you debug with a breakpoint in _runThread, what happens is that when it
hits the breakpoint, it pauses for a LONG time in the debugger (10-15
seconds) and then brings you to that breakpoint... but if you try to
"step over", it just kicks out of the thread with an error message in
the output of "A first chance exception of type
'System.Threading.ThreadAbortException' occurred in
System.Windows.Forms.dll" in the output window and the thread is gone.

Does anyone have any idea why this is happening? Is it something I'm
doing wrong in my code? It doesn't matter WHAT I am trying to do in
the _runThread method, ANY code which I attempt to debug will give me
that ThreadAbortException if I try to debug. But it runs just fine if
I run it without any breakpoints. And I can debug on the UI thread
without any problems at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top