Re: Wried problem
- From: "leiz" <leizhao831@xxxxxxxxx>
- Date: 19 Sep 2006 17:01:43 -0700
Thank you very much. Now I understand what is going on there. I thought
NTA was windows2k only because of the statement in the dialog when you
create ATL objects. :p
I am kinda new to C#. Are there any methods to comparing two objects
across apartments.
Willy Denoyette [MVP] wrote:
"Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
news:%23AFxhM82GHA.1060@xxxxxxxxxxxxxxxxxxxxxxx
|
| "leiz" <leizhao831@xxxxxxxxx> wrote in message
| news:1158625241.204727.214560@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|| If I understand you correctly, as along as I dont use Form and set the
|| main thread to MTA, the result would be true, right?
||
|
| Right.
|
|| I think that the problem is that the event handler is called by some
|| threads created by c# are in different apartment. However, when I print
|| out the ApartmentState in the event handler, it is a MTA, so they
|| should be in same apartment. Therefore, the objects should be same.
||
|
| No they don't. The callback (the Sink interface) is running on a
ThreadPool
| thread which is created by the COM interop layer (through a CCW). The CCW
| aggregates the free threaded marshaler and initializes the thread as NTA
| (Neutral Threaded Apartment) which is always the case when you expose .NET
| classes to COM clients.
| That means that the callback can run on any thread, it has no apartment
| requirements at all. The GetApartmentState returns MTA because it treats
| both as compatible, but I would prefer the more correct NTA instead of
MTA.
| Anyway the context differs from the MTA context.
| But, I guess you have a wrong idea about the references you are comparing
| and what they point at.
| app and m_WordApp are references to an object of type Word.Application,
| however, this is not a reference to a COM object. It's a reference to a
| context object (one per apartment type in the process) that holds a
| hashtable holding RCW's which represents the real IUnknow/IDispatch COM
| object interface.
| So, when you compare app with m_WordApp, you compare whether they use the
| same context, however, when they are equal, that doesn't mean that the COM
| interfaces (the RCW) are the same, they are NOT. And because the RCW's
| aren't the same doesn't mean that the object they refer to are different,
| you see?
| Honestly, I don't see what you are after by comparing these reference
| really.
|
|
| Willy.
Correction, after re-reading I noticed following error in above.
The callback (the Sink interface) is running on a ThreadPool
thread which is created by the COM interop layer (through a CCW).
This should read...
The callback (the Sink interface) is running on a native
thread which is created by the COM interop layer (through a CCW).
Willy.
.
- Follow-Ups:
- Re: Wried problem
- From: leiz
- Re: Wried problem
- From: Willy Denoyette [MVP]
- Re: Wried problem
- References:
- Wried problem
- From: leiz
- Re: Wried problem
- From: Willy Denoyette [MVP]
- Re: Wried problem
- From: leiz
- Re: Wried problem
- From: Willy Denoyette [MVP]
- Re: Wried problem
- From: leiz
- Re: Wried problem
- From: Willy Denoyette [MVP]
- Re: Wried problem
- From: leiz
- Re: Wried problem
- From: Willy Denoyette [MVP]
- Re: Wried problem
- From: Willy Denoyette [MVP]
- Wried problem
- Prev by Date: Help with PInvoke of a struct
- Next by Date: Re: SQL WHERE Command Help [C# Win]
- Previous by thread: Re: Wried problem
- Next by thread: Re: Wried problem
- Index(es):
Relevant Pages
|