473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Detach an event based on an anonymous method?

Hi, is it possible to detach an event which is implemented via an anonymous
method.

ie. If the code is:
myObject.myEvent += delegate(object sender, EventArgs e) {
// snip event actions
}

is there a way that I can I detach this later via -=, or do I need to use a
named event?

thanks
Barry Mossman
Sep 24 '06 #1
1 2744
Barry,
>Hi, is it possible to detach an event which is implemented via an anonymous
method.
Only if you keep a reference to the delegate.

EventHandler x = delegate(object sender, EventArgs e) {
// snip event actions
}
myObject.myEvent += x;
....
myObject.myEvent -= x;
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 24 '06 #2

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

Similar topics

7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
3
by: | last post by:
Is there an event that is invoked when a user sorts a column in a Windows Forms DataGrid? I have context senstive icons that are enabled\disabled depending upon the selected item in the...
19
by: Heidi Hundåla | last post by:
Hi ! I have a Wep App in C#. Page_Unload fires after Page_Load, and it seems totally unreasonable when you want to use this event when you _leave_ the page. In my project we wanted to use...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
7
by: moondaddy | last post by:
I'm reading the book Wrox-Professional C# 2005 and it's trying to demonstrate an anonymous method in an event handler. I would not do this in a real app, but am trying to understand how this...
2
by: Sin Jeong-hun | last post by:
Suppose class Engine do something in another thread and raise events. class Engine { Thread Worker; public event ... EngineMessage; public void Start() { Worker=new Thread(new...
11
by: AAaron123 | last post by:
newItem and tsMenuItem are ToolStripMenuItems. I'd like to add the click event in tsMenuItem to newItem. Can't do this because Events is Protected: ...
9
by: dpatel75 | last post by:
I am trying to copy a database from a SQL 2000 SP3 Windows 2000 server to a 2005 SP2 Windows 2003 server. I am trying to use detach and attach method (have tried both within Management Studio and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.