views:

23

answers:

0

I'm using a BackgroundWorker to do some work. Part of that work involves showing a form. That form has some controls that are set as drag & drop targets.

I know that the BackgroundWorker uses the ThreadPool to run, and that threads from the thread pool use the MTA threading model. I also know (thanks to this question) that when you have a control that uses drag & drop, there's some COM interop happening, and that when you have that sort of COM interop happening, the thread that owns the control involved with the COM interop stuff has to use the STA threading model (which you can't get from a BackgroundWorker).

Unfortunately, what I don't know is why I get a ThreadStateException only when the program is run outside of the debugger. When I run it from the Visual Studio IDE (using the debugger, both with the Visual Studio hosting process turned on and with it turned off), no exception happens.

Is there something different about the thread pool that a BackgroundWorker draws from when run under the debugger vs. when run normally? Or is there some other reason why the ThreadStateException (which I expect to see, given what this question says) doesn't happen in the debugger?