Re: Unsubscribing from events.

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 03/15/05


Date: Tue, 15 Mar 2005 10:29:21 -0500

Pete,

    Yes, it works. I wouldn't waste the field to hold onto this. It's the
method that is the identity of the delegate, not the instance of the
delegate itself.

    Hope this helps.

-- 
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com
"Pete Davis" <pdavis68@NOSPAM.hotmail.com> wrote in message 
news:87adnUDn277vYKvfRVn-ow@giganews.com...
>I came across the following code in the .NET Framework:
>
> ((IBindingList) list).ListChanged -= new
> ListChangedEventHandler(this.List_ListChanged);
>
> In other places, they hold onto a reference to the original event handler
> instance and unsubscribe that. I've always held the references and
> unsubscribed the original myself.
>
> Unsubscribing from a new instance instead of the original instance just
> seems wrong. Yet one of my co-workers claims this actually works. Does it?
>
> Pete
>
> 


Relevant Pages

  • Re: Messages for a resource are sent to a non-existent account
    ... Susan Conkey [MVP] ... Exchange Server 2003 a resource account with a calendar. ... reference to her in any address book or as a remaining delegate. ... other cached data there is an invalid reference to Person A, ...
    (microsoft.public.exchange.admin)
  • Re: Ahh not again!
    ... Can anyone explain to my the life cycle for a delegate and when it is created on the control - or if there is another approach for creating events/delegates. ... If something has a reference to the delegate, ... If you'd actually subscribed a delegate to the event, it would remain subscribed until you unsubscribe it. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Unsubscribing from events.
    ... Pete ... > method that is the identity of the delegate, ... they hold onto a reference to the original event ... >> instance and unsubscribe that. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Generic Delegate Types explained (example)
    ... Unless you have specifically stated that the generic type has to be a value type, it can always be a reference type. ... To change the value of a string you have to replace it with a new string instance, which you can not do unless you send the string by reference to the method. ... example of generic delegate types taken from p. 108 of the C# 3.0 ... static Util UtilStringChanger2AndMoreStaticVersion ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: multithreaded tcp/ip monitoring application
    ... Passing a copy of a reference type variable just passes the reference, and so mutations in the instance can still be seen by multiple threads. ... The string type is a reference type, but a string instance is immutable and the string class is thread-safe. ... the variable itself is mutable and that's why you need the synchronization. ... But, and this is very important, the "str" variable itself is not referenced by the invoked delegate. ...
    (microsoft.public.dotnet.languages.csharp)