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 [STAThread] attribute for windows/console applications
3 - use System.Thread.C urrentThread.Ap artmentState =
ApartmentState. STA
The problem is that the COM object is only called through a business
layer module. This business layer consists of a number of classes that
encapsulate the calls to the COM object. Therefore, option 1 and 2 are
not applicable and option 3 does not work since the threading model
has already been defined even before the class initializer is called.
One solution that I've come up with is calling a 'stub' method for
each method in the business layer. This 'stub' will declare a new
thread, set the apartment model to STA, then start the thread. This is
tedious because every method will require a 'stub' and all parameters
(in and out) must be handled through private class members. I can't
imagine that this is the proper way of doing things.
So, my question is: Is there a way to make the entire class
single-threaded by default (similar to [STAThread] for a windows app)?
Any help would be greatly appreciated.
Rob. 2 1710
no, if a class is not thread safe, it has no way of enforcing it, it up to
the caller. the 3 methods you list are for ensuring the caller (a thread)
does not do a thread switch.
your solution is the correct one, except, that the stubs should only create
one STA thread, then switch to that thread to make the call, unless the com
object is completly stateless.
-- bruce (sqlwork.com)
"Rob" <ro**********@h otmail.com> wrote in message
news:ad******** *************** **@posting.goog le.com... 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 [STAThread] attribute for windows/console applications 3 - use System.Thread.C urrentThread.Ap artmentState = ApartmentState. STA
The problem is that the COM object is only called through a business layer module. This business layer consists of a number of classes that encapsulate the calls to the COM object. Therefore, option 1 and 2 are not applicable and option 3 does not work since the threading model has already been defined even before the class initializer is called.
One solution that I've come up with is calling a 'stub' method for each method in the business layer. This 'stub' will declare a new thread, set the apartment model to STA, then start the thread. This is tedious because every method will require a 'stub' and all parameters (in and out) must be handled through private class members. I can't imagine that this is the proper way of doing things.
So, my question is: Is there a way to make the entire class single-threaded by default (similar to [STAThread] for a windows app)?
Any help would be greatly appreciated.
Rob.
Thanks Bruce.
"bruce barker" <no***********@ safeco.com> wrote in message news:<#z******* *******@TK2MSFT NGP12.phx.gbl>. .. no, if a class is not thread safe, it has no way of enforcing it, it up to the caller. the 3 methods you list are for ensuring the caller (a thread) does not do a thread switch.
your solution is the correct one, except, that the stubs should only create one STA thread, then switch to that thread to make the call, unless the com object is completly stateless.
-- bruce (sqlwork.com)
"Rob" <ro**********@h otmail.com> wrote in message news:ad******** *************** **@posting.goog le.com... 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 [STAThread] attribute for windows/console applications 3 - use System.Thread.C urrentThread.Ap artmentState = ApartmentState. STA
The problem is that the COM object is only called through a business layer module. This business layer consists of a number of classes that encapsulate the calls to the COM object. Therefore, option 1 and 2 are not applicable and option 3 does not work since the threading model has already been defined even before the class initializer is called.
One solution that I've come up with is calling a 'stub' method for each method in the business layer. This 'stub' will declare a new thread, set the apartment model to STA, then start the thread. This is tedious because every method will require a 'stub' and all parameters (in and out) must be handled through private class members. I can't imagine that this is the proper way of doing things.
So, my question is: Is there a way to make the entire class single-threaded by default (similar to [STAThread] for a windows app)?
Any help would be greatly appreciated.
Rob. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matthew Bell |
last post by:
Hi,
I've got a question about whether there are any issues with directly
calling attributes and/or methods of a threaded class instance. I
wonder if someone could give me some advice on this.
Generally, the documentation suggests that queues or similar constructs
should be used for thread inter-process comms. I've had a lot of
success in doing that (generally by passing in the queue during the
__init__ of the thread) and I can see...
|
by: Robb Gilmore |
last post by:
We inherited an ASP.NET application which is not thread-safe. Many copies of
this application are in the field and customers are having problems, which we
believe is due to the thread safety problem.
Is there any way to configure IIS to run single-threaded, so that these
customers can get along without errors until we can get them updated software?
Some will have IIS 5.0 ( Win2K and WinXP ) and some will have IIS 6.0 (
Win03 ). For...
|
by: Martin Ink |
last post by:
I have a program linked to an .exe and this program is started from an
other program.
I would like to control the execution of the program so that the
program only runs 'single threaded'. I don't want simultaneously
session of my program to be run.
My program must be an .exe.
Is there a way to control this in a simple way ??
Rgds
|
by: Ranju. V |
last post by:
Hi,
I use a lot asynchronous XMLHTTP from JavaScript. Are the callbacks
that we register with XMLHTTP guaranteed to execute single-threaded?
For instance, consider the following code snippet.
var xmlhttp1 = new ActiveXObject( "Msxml2.XMLHTTP.4.0" );
xmlhttp1.onreadystatechange = callback;
xmlhttp1.open( "POST", "foo.aspx", true );
xmlhttp1.send( data1 );
|
by: ben |
last post by:
I am needing a web service to be single threaded. Is this possible? Any
ideas would be helpful
| |
by: Rsrany |
last post by:
I've been working on a few gtk applications and need to tie a hot key
catcher into a thread. I am currently finding threaded
user32.GetMessageA do not work.
I have included two programs:
1) a non-threaded version that works
2) a threaded version that doesnt work.
Any constructive suggestions would be helpful
|
by: mhdostal |
last post by:
I have a multi-threaded application using both managed (C#/.NET) and
unmanaged code (C++). The unmanaged code calls into the manage code
(via COM Interop) to perform a variety of tasks. Every two or three
days the application would unexpectedly crash; I added a GC.Collect()
call to the end of every method in the module in question and now the
problem happens 4 -5 time a day. Some debug information from WinDbg is
below. I'm currently...
|
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...
|
by: Chris Thomasson |
last post by:
Here is the code:
http://pastebin.com/m4a405e67
One advantage to using a region allocator is that you can usually skip most
calls to free. Instead you can merge multiple free calls into a single reset
call. Here is simple example:
___________________________________________________________________
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |