473,785 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can BackgroundWorke r 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 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?
Jul 21 '08 #1
2 11870

"Harry Keck" <Ha*******@disc ussions.microso ft.comwrote in message
news:F0******** *************** ***********@mic rosoft.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 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?
Which VB (classic or dotNet) are you using?
Jul 21 '08 #2
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

Jul 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1707
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" for aspx pages 2 - use attribute for windows/console applications 3 - use System.Thread.CurrentThread.ApartmentState = ApartmentState.STA
6
4964
by: ben | last post by:
I am needing a web service to be single threaded. Is this possible? Any ideas would be helpful
8
4855
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 I want to raise the ProgressChanged-event to update the DataGridView. It works fine when only one Progresschanged is fired, but at the second, third, fopurth etc it raises everytile a 'Cross-thread operation not valid"-exception on lmy...
11
2844
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 application starts up it is a requirement for the user to log on, so in my magical wisdom, I thought shove all this processing on another thread, so it loads while the user logs on. I have all the code running on the thread OK, but I cannot figure out how...
5
14134
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 my FileIO class) I've established Public Event in my core logic classes along with RaiseEvents (that will updated a progress bar on the UI side). This all works great when I'm NOT using Threading (BackgroundWorker), however, as soon as I...
6
16332
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 instance of the form, I get this error message: --------------------------- ActiveX control '243f57b7-dd96-4179-865d-27ac7b5df609' cannot be instantiated because the current thread is not in a single-threaded apartment. ---------------------------
9
18036
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 will almost always lead to the user opening a certain child window that's fairly resource intensive to load. Is it possible to load this form in a backgroundworker and then use the Show method and hide method as necessary? Anyone know of
0
1602
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 to run in STA rather than MTA mode? When I try to instantiate a form object from a class with no form, I get an exception of "control cannot be instantiated because the current thread is not in a single-threaded apartment". When I put...
2
3889
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 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?
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8986
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.