----- Original Message -----
From: "J. Merrill" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, September 12, 2003 7:39 PM
Subject: Re: [ADVANCED-DOTNET] Object identities, marshaling issues and
interoperability


> Wouldn't using the string parameter to externalObject.Item as the key
solve your problem?  You would not store the Item value (a reference to a
.NET object wrapping the COM item) in the hash table at all.  As you've
discovered, the usefulness of that value is limited due to different threads
having different .NET wrappers for the same COM object.
>
> During a callback, get the "name" (or whatever the .Item parameter string
is called) from the passed-in Item and use that to retrieve your app's
associated info from the HashTable.  (Any info about the Item that you
need -- that your app doesn't store -- could be retrieved from the passed-in
Item.)
>
> Do you really need to hold on to the Item reference value for some reason?
(I don't know what that would be, since the value can't be used by both
threads.)  If you do, you could possibly record _both_ the child thread's
Item value and the GUI thread's Item value in your app's data.  Whether it
was the child thread or the GUI thread that first saw the particular Item,
it would record its thread-specific Item value in "its" slot and leave the
other (default NULL) alone.  But I don't really think you'd ever need this.
>
> Of course, you might have confused me by using "MyItem" as the .Item
parameter, when perhaps it's something that could change and thus can't be
used as the HashTable key on the .NET side (ugh).

   Yes, and I am sorry for being so unclear. I used "MyItem" as the .Item
parameter just for illustration. In reality, Items form a hierarchy, so the
typical code to get an item looks like follows:
...
      Item item;
      Item subItem = item.GetSubItemByIndex (2);
...

  My wrappers mimic the hierarchy by holding a reference to the underlying
item and delegating calls to this reference:
....
   class ItemWrapper
   {
       Item myItem;

       ItemWrapper GetSubItemByIndex (int index)
       {
          Item item = itemToWrapperTable [myItem.GetSubItemByIndex (index)];
// (*) Item.GetSubItemByIndex returns different stubs for the same member

// of the hierarchy on different threads
       }
   }
....
     ItemWrapper wrapper;
     ItemWrapper subItemWrapper = wrapper.GetSubItemByIndex (2);
....

  In line (*) I get two different wrappers depending on what thread now
executes the code. It is OK, I do not really need ItemWrappers to be unique.
However, I need
  a way to provide correct Equals () and GetHashCode () methods for
ItemWrapper class. "Correct" means that the methods should treat different
ItemWrappers which
  represent the same member of the hierarchy as equal. Unfortunately, Item
does not expose the unique identifier among its properties, so using some
kind of apartment-
  independent identifier of Item seems to be the only way to implement both
methods.

>
> At 05:03 PM 9/12/2003 +0400, Dmitry Shaporenkov wrote
> >----- Original Message -----
> >From: "Ron O'Rourke" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Sent: Friday, September 12, 2003 4:24 PM
> >Subject: Re: [ADVANCED-DOTNET] Object identities, marshaling issues and
> >interoperability
> >
> >> Assuming you have the ability to modify the Item code [snip]
> >
> >    I can't change Item implementation. Well, when I was talking about
some
> >information
> >    in the Hashtable, this information was really a wrapper around Items,
> >and the Hashtable contains
> >    mapping from Items to corresponding wrappers. Even having Items
wrapped,
> >I still sometimes need
> >    to get the wrapper for an Item. In particular, this happens when the
UI
> >thread receives an event from the
> >    external component and the event contains an Item as an argument. The
UI
> >thread hence accesses the hashtable
> >    to get the wrapper, and the problem arises.
> >
> >>
> >> On Fri, 12 Sep 2003 13:25:27 +0400, Dmitry Shaporenkov wrote:
> >>
> >> >Hi all,
> >>
> >> <Snip>
> >>
> >> >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.
> >>
> >> <Snip>
> >>
> >> >Any advices / references will be greatly appreciated. Thanks in
advance.
> >> >
> >> >Regards,
> >> >Dmitry Shaporenkov
>
>
> J. Merrill / Analytical Software Corp
>
> ===================================
> 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

===================================
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

Reply via email to