Hi all,
I need help in a problem concerning COM/.NET interoperability in a
multithreaded application.
The application (written in C#) uses an external component which exposes
COM-based object model.
Let's say 'Item' is an object of the model, item has a __CComObject type.
Items are accessed via calls to the component like the follows:
....
Item anItem = externalObject.GetItem ("MyItem");
....
During startup a worker thread is running to collect some information about
items and store it in a hashtable (using items as the keys):
....
Hashtable theCache = new Hashtable ();
theCache [anItem] = <something>;
...
The information is then used from code executing in the UI thread:
...
Item anItem = externalObject.GetItem ("MyItem");
<something> = theCache [anItem]; // Oops. This does not work
...
The problem is that, because UI thread lives in a STA and the worker thread
executes in another apartment,
the UI thread gets different wrapper than the worker thread, since items are
marshalled across apartments. I realize that this is normal behavior.
However, I need a way to identify items in a thread-independent fashion.
Items themselves do not have any properties which might serve as a reliable
unique identifiers.
So, the question is, how such problems are resolved? May be there is still a
way to get apartment-independent identifier of the object? I am not a COM
guru,
but I took a look at System.Runtime.InteropServices.Marshal class and found
nothing similar.
Any advices / references will be greatly appreciated. Thanks in advance.
Regards,
Dmitry Shaporenkov
mailto:[EMAIL PROTECTED]
===================================
This list is hosted by DevelopMentor╝ http://www.develop.com
NEW! ASP.NET courses you may be interested in:
2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet
Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet
View archives and manage your subscription(s) at http://discuss.develop.com