On Mon, 21 Jul 2008 06:36:01 -0700, Harry Keck
<Ha*******@disc ussions.microso ft.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 BackgroundWorke r object, which seems to be
on a
MTA thread. Is there a way for me to get the BackgroundWorke r thread to
run
in STA mode, or do I have to remove the BackgroundWorke r and hand spin
my own
async call?
BackgroundWorke r will typically use the thread pool, and AFAIK those are
always MTA threads. Even if they're not, forcing the current
BackgroundWorke r thread to be STA could cause other things to break,
because the threads are shared.
In other words, I think that not using BackgroundWorke r 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