On Mon, 21 Jul 2008 06:36:01 -0700, Harry Keck
<Ha*******@discussions.microsoft.comwrote:
I have introduced a component to my solution that is throwing an
exception
about needing to be run in single threaded apartment mode. This
component is
created in an async call by a BackgroundWorker object, which seems to be
on a
MTA thread. Is there a way for me to get the BackgroundWorker thread to
run
in STA mode, or do I have to remove the BackgroundWorker and hand spin
my own
async call?
BackgroundWorker will typically use the thread pool, and AFAIK those are
always MTA threads. Even if they're not, forcing the current
BackgroundWorker thread to be STA could cause other things to break,
because the threads are shared.
In other words, I think that not using BackgroundWorker is the correct
approach. If you have to have an STA thread, you should create your own
thread for the purpose so that you can control its apartment model
explicitly.
Pete