473,321 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 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 11807

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob | last post by:
Hi. I'm having difficulty calling a 3rd party COM object that must be called in the apartment (single) threaded model. As far as I know, there are 3 ways todo this: 1 - use "aspcompat=true"...
6
by: ben | last post by:
I am needing a web service to be single threaded. Is this possible? Any ideas would be helpful
8
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item...
11
by: Jamie Bissett | last post by:
I have an application that creates a pretty intensive TreeView at startup time. I had the program running on a single thread sucessfully, but the startup time was a bit excessive. When the...
5
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in...
6
by: Dustin Davis | last post by:
I've build an application that monitors a folder. When a new file is created in that folder it kicks off a process. On such process is to load a form. When I get to the statement to create and...
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
0
by: mike1reynolds | last post by:
While my project is in an STA state, when I added a class with no form it is executing in an MTA state. I can't find any reference to MTA or STA anywhere in the entire solution. How do I set a class...
2
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, 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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.