473,785 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clear invokation list

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.GetInvoca tionList();
Delegate.Remove All(MyDel, tmp[0]);

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

What am I missing?

Thanks,
Lubomir

Apr 27 '07 #1
3 7141
Hi,
delegates are immutable, you cannot change their contents, only create new
instances. The Delegate.Remove All 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.GetInvoca tionList();
Delegate.Remove All(MyDel, tmp[0]);

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

What am I missing?

Thanks,
Lubomir
Apr 28 '07 #2
Lubomir <Lu*****@discus sions.microsoft .comwrote:
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.GetInvoca tionList();
Delegate.Remove All(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 - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 28 '07 #3
Thanks for help.

Lubomir

"Jon Skeet [C# MVP]" wrote:
Lubomir <Lu*****@discus sions.microsoft .comwrote:
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.GetInvoca tionList();
Delegate.Remove All(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 - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9320
by: scooter | last post by:
std::list::clear() can slow down the performance of a method considerably if it is called many times a second. I have countered this problem a little by assigning a fixed size to a list when instantiated and keeping track of the elements through iterator logic. This seems a little messy to me though. I'm sure the guys who created the STL must have a speedier method. How do you guys clear and reuse a std::list multiple times with as...
0
881
by: lucasimone | last post by:
Hi, i need some help to a pocket PC application. I need to implement a Form that contains a WebBrowser to display somes HTML forms. But when users invoke a submit, of that form, i need to capture the invokation, and process it, with a Visual C# methot, before it will sent to the net! Anyone can give me a solutions! Best regards! Luca
9
3190
by: fudmore | last post by:
Hello Everybody. I have a Segmentation fault problem. The code section at the bottom keeps throwing a Segmentation fault when it enters the IF block for the second time. const int WORDS_PER_LINE = 4; when counter == 7 is when the string Concatenation fails within the IF block.
2
3591
by: Ryan | last post by:
I have a dropdown list bound to a datasource. I would like to clear it at the press of a button. I tried using the following code: mydropdown.Items.Clear() The end result is that it comes back unchanged. I then thought to myself maybe it has to do with the viewstate so I I kept adding more and more code until I ended up with the following:
77
17062
by: Ville Vainio | last post by:
I tried to clear a list today (which I do rather rarely, considering that just doing l = works most of the time) and was shocked, SHOCKED to notice that there is no clear() method. Dicts have it, sets have it, why do lists have to be second class citizens?
3
2145
by: Andrew V | last post by:
Greetings, I need to create a web service to be called by a few of our external affiliated web sites. How can I restrict web service invokation to only these affiliated web sites? Some of the things I came up with, but seems weak 1. Check caller's url and only accept those that are in a list of authorized web sites. But hacker can spoof the url 2. Give each site a user name and password to send over with every call. But
19
7238
by: Krishanu Debnath | last post by:
Hello, I have a call to hash_map::clear() function which takes long time. someClass::someFunction() { // typedef hash_map<name_id, uintMp; // Mp p; // assuming proper namespace, hash function for name_id obj.
35
5895
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the list. That part makes a reasonable amount of sense, as you can't actually take items away from an Array. However, there doesn't seem to be a way to perform the same operation in one fell swoop on a List<>. For example:
1
2080
by: woshicike | last post by:
Hi, I created a web service. When I place it under visual studio development server, the asynchronous invokation of web methd works fine. But when I publish the web service under IIS 5.1, the asynchronous invokation of web method doesn't work. Does anybody have some comments?
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.