471,354 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Can BackgroundWorker be Single Threaded Apartment?

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?
Jul 21 '08 #1
2 11640

"Harry Keck" <Ha*******@discussions.microsoft.comwrote in message
news:F0**********************************@microsof t.com...
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?
Which VB (classic or dotNet) are you using?
Jul 21 '08 #2
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

Jul 21 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Rob | last post: by
6 posts views Thread by ben | last post: by
11 posts views Thread by Jamie Bissett | last post: by
6 posts views Thread by Dustin Davis | last post: by
2 posts views Thread by =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.