PC Review


Reply
Thread Tools Rate Thread

clear invokation list

 
 
=?Utf-8?B?THVib21pcg==?=
Guest
Posts: n/a
 
      28th Apr 2007
Hi,

I am wondering how I could clear the invokation list of delegates.

I tried the following:

//make a chain
MyDel += SomeDel;

// Clear the chain
Delegate [] tmp = MyDel.GetInvocationList();
Delegate.RemoveAll(MyDel, tmp[0]);

Nothing (not even one delegate) is removed from the list.

What am I missing?

Thanks,
Lubomir



 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFyayBSLiBEYXdzb24=?=
Guest
Posts: n/a
 
      28th Apr 2007
Hi,
delegates are immutable, you cannot change their contents, only create new
instances. The Delegate.RemoveAll method will remove all occurances of the
specified delegate from the provided delegate and return you a new delegate
instance. So in your example you want to be using the return value from the
RemoveAll method.

Thanks
Mark.
--
http://www.markdawson.org


"Lubomir" wrote:

> Hi,
>
> I am wondering how I could clear the invokation list of delegates.
>
> I tried the following:
>
> //make a chain
> MyDel += SomeDel;
>
> // Clear the chain
> Delegate [] tmp = MyDel.GetInvocationList();
> Delegate.RemoveAll(MyDel, tmp[0]);
>
> Nothing (not even one delegate) is removed from the list.
>
> What am I missing?
>
> Thanks,
> Lubomir
>
>
>

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      28th Apr 2007
Lubomir <(E-Mail Removed)> wrote:
> I am wondering how I could clear the invokation list of delegates.


You can't change an existing delegate - it's immutable.

> I tried the following:
>
> //make a chain
> MyDel += SomeDel;
>
> // Clear the chain
> Delegate [] tmp = MyDel.GetInvocationList();
> Delegate.RemoveAll(MyDel, tmp[0]);
>
> Nothing (not even one delegate) is removed from the list.
>
> What am I missing?


As I say, delegates are immutable - think of them as being like strings
in that respect.

See http://pobox.com/~skeet/csharp/events.html for more details.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
=?Utf-8?B?THVib21pcg==?=
Guest
Posts: n/a
 
      30th Apr 2007
Thanks for help.

Lubomir



"Jon Skeet [C# MVP]" wrote:

> Lubomir <(E-Mail Removed)> wrote:
> > I am wondering how I could clear the invokation list of delegates.

>
> You can't change an existing delegate - it's immutable.
>
> > I tried the following:
> >
> > //make a chain
> > MyDel += SomeDel;
> >
> > // Clear the chain
> > Delegate [] tmp = MyDel.GetInvocationList();
> > Delegate.RemoveAll(MyDel, tmp[0]);
> >
> > Nothing (not even one delegate) is removed from the list.
> >
> > What am I missing?

>
> As I say, delegates are immutable - think of them as being like strings
> in that respect.
>
> See http://pobox.com/~skeet/csharp/events.html for more details.
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To clear the Open Other User's Folder list & To clear the Find a Contact list JW Microsoft Outlook 1 30th Jan 2008 07:19 PM
Array.Clear vs List<>.Clear Lee Crabtree Microsoft C# .NET 43 8th Oct 2007 08:11 PM
Help on external process invokation in VC++ Chaw-Chi Yu Windows XP General 2 19th Jan 2007 01:35 PM
Method invokation list =?Utf-8?B?TWFya3VzIFA=?= Microsoft Dot NET 0 11th Jun 2004 10:05 AM
Constructor invokation Alex Microsoft C# .NET 3 25th Aug 2003 06:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:34 PM.