bug vs2005?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Some production code works fine under vs2003 but has problems under vs2005.
The code runs fine outside the debugger but inside there are places where the
debugger hangs for about 15 seconds, hits a breakpoint, but any other step
will cause the thread to die. I created a sample app which reproduces the
problem. The basic steps are

1. have the main gui thread store the main form in a variable in a worker
class
- the worker class will mostly run on a separate thread
1. have the main gui thread perform a BeginInvoke on a delegate to run
the worker thread
2. in that delegate we will see problems if we do any of the following:
a. inspect the form variable on the worker thread - the debugger will
hang for about 15 seconds and then things are in a bad state
-OR-
b. call a method passing the form - again things hang for about 15sec

I know a separate thread is not supposed to directly access controls
from outside the gui thread but this seems to be a debugger problem
since the test code below doesn't directly access any controls.

Here's the code:


namespace ThreadTest
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

public void CallBack( Form f )
{
}

private void Form2_Load( object sender, EventArgs e )
{
Worker w = new Worker( this );
ThreadDelegate td = new ThreadDelegate( w.Work );
td.BeginInvoke( null, null );
}

delegate void ThreadDelegate();
}

public class Worker
{
public Worker( Form2 f )
{
this.f = f;
}

public void Work()
{
//f.CallBack( f ); causes problems w/ debugger

// also inspecting f in debugger causes problems

Debug.WriteLine( "test" );
Thread.Sleep( 1000 );
Debug.WriteLine( "test2" );
}

Form2 f;
}
}


Is this a known problem?

thanks,
Paul.


.