473,231 Members | 1,558 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,231 software developers and data experts.

Detecting cross-apartment COM calls?

I was wondering if there was a utility that could tell you when your C#
application is making cross-apartment COM calls. I have a fairly large
application that makes extensive use of a 3rd party object system that
is exposed to .NET through COM, and I'm really trying to avoid slow
cross-apartment calls.

Also, is using Invoke() on a class created from the main thread a
solution to making COM calls into that thread?

Thanks.

-- James

Mar 19 '06 #1
3 2294

<jl******@gmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
|I was wondering if there was a utility that could tell you when your C#
| application is making cross-apartment COM calls. I have a fairly large
| application that makes extensive use of a 3rd party object system that
| is exposed to .NET through COM, and I'm really trying to avoid slow
| cross-apartment calls.
|
No, there is no such a 'utility', if you want to prevent any
cross-apartment- cross-thread calls you have to make sure your COM objects
live in a 'compatible' apartment and that you access the object from the
creators thread only.
| Also, is using Invoke() on a class created from the main thread a
| solution to making COM calls into that thread?
|

If you mean Control,Invoke, the answer is no, this method is meant to
dispatch delegates to the UI thread, this has nothing to do with
cross-thread COM calls.
The CLR will automagically marshal the Interface pointer when calling a COM
method using an object reference (a RCW) from another thread as the
creator's thread, so you don't hav to take care of this.

Willy.

Mar 19 '06 #2
Ok.
My problem is that I have threads that I spawn (using System.Threading)
that need to access these COM objects, so I was wondering the best way
to invoke the methods on these COM objects from the creation thread but
get the results back to the other thread (similar to what Invoke() does
for UI components).

Mar 19 '06 #3

<jl******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
| Ok.
| My problem is that I have threads that I spawn (using System.Threading)
| that need to access these COM objects, so I was wondering the best way
| to invoke the methods on these COM objects from the creation thread but
| get the results back to the other thread (similar to what Invoke() does
| for UI components).
|

The best way to prevent cross-apartment/cross-thread marshaling is by
accessing the objects from the same compatible thread that created them.
Only 'Free' and 'Both' threaded (ThreadingModel = Free/Both) object
references can freely be passed across threads without incurring
cross-thread marshaling provided they are created/accessed from MTA threads.
'Apartment' object types take no marshaling hit when accessed from the
creating (STA)thread, you always pay for marshaling when their reference is
passed to another thread (STA or MTA).

Willy.
Mar 19 '06 #4

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

Similar topics

3
by: Alessandro Crugnola *sephiroth* | last post by:
Hi, i'm using wxPython and wxTextStyled. How can I intercept document changes for active documents (for example modified with others external editors)? thanks in advance -- Alessandro...
1
by: bill ramsay | last post by:
Dear all. I am using an existing hodge-podge of an application that runs on top of an Access database. This application dials up customer equipment, handshakes then downloads/uploads various...
9
by: Kevin Frey | last post by:
Hello, Can anyone suggest a way, that does not involve writing a temporary file, that would permit me to discover whether writing: output_file_stream << '\n'; will write either a LF (eg....
5
by: Steve | last post by:
Hi everyone, I'm trying to make an openGL app (in visual c++) that allows the use of two mice simultaneously. Does anyone know if this is possible, how I might go about doing it or how I could...
2
by: Halldór Ísak Gylfason | last post by:
In my application I have an iframe that is empty (and not visible) initially, however when a user presses a button a form is programmatically submitted and the target is set to the IFrame. I...
5
by: Rich | last post by:
I have a simple, single threaded program in C++ that runs as Idle priority. The program creates some data which needs dumping to file if the computer is shutdown or logged out. At the moment...
20
by: Mandy Memphis | last post by:
If I perform a mousedown within a document, move the mouse outside the browser window, and then release the mouse button, the document.onmouseup event does not fire. Is there any way to detect a...
1
by: Stuart | last post by:
The following code works well in monitoring the mouse position in its own frame, I need to capture the mouse position when it is over another frame, What is the correct syntax? There is two...
25
by: Ryan Stewart | last post by:
I'm working on a project to collect web application usage statistics. What are the recommended ways of detecting whether a browser is JavaScript enabled and/or capable? Obviously I can write a...
7
by: BWill | last post by:
Hi, I'm writing a file browser, but I'm not sure how I could go about detecting the drives available on windows and linux systems (preferably using the standard modules if possible). I guess I...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.