473,320 Members | 1,832 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,320 software developers and data experts.

how to check if a method has already been added as handler of particularevent?


subject says it all.
thanks in advance.

Ivan
Nov 17 '05 #1
1 2152
Ivan,

Are you doing this inside or outside of the class that is exposing the
event. If it is outside, then you would have to use reflection to get to
the delegate that is being stored internally (the C# compiler will not let
an event appear on the right hand side of an assignment expression).

If this is internal, then you can use the syntax for events which allows
you to write extra code, like so:

// Need to store the event in a field to prevent compiler error.
// Also, you will have to check against null when you want to use it.
private EventHandler myEvent;

public event EventHandler MyEvent
{
add
{
// Write code to check the value (like in a property)
// to see if the event handler points to a method info you might
// already have in your invocation list.

// If the check succeeds, then add the handler.
myEvent += value;
}
remove
{
// Remove the delegate.
MyEvent -= value;
}
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ivan" <iv*********@dynamic-imaging.com> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...

subject says it all.
thanks in advance.

Ivan

Nov 17 '05 #2

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

Similar topics

16
by: Steve Jorgensen | last post by:
I'm trying to figure out if there is a way to generate standard error handlers that "know" if the calling code has an error handler in effect (On Error Goto <label> or On Error Resume Next) before...
0
by: Alex Zhitlenok | last post by:
I found out that if you subscribe to or unsubscribe from an event in the method that gets event handler as a parameter, it does not work as expected. If the event is declared as event...
3
by: Casper Skovgaard | last post by:
I have a form with several fields (textbox, radio, checkbox), when the user submits the form I want to check if the user have changed anything. The check should be performed in the code-behind...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
25
by: pamelafluente | last post by:
Hi Guys, I have the following HTML code which is doing a GET to a page, say MyUrl.aspx : <body> <form name="form1" method="get" action="MyUrl.aspx" id="form1"> <input type="hidden"...
5
by: rn5a | last post by:
The .NET 2.0 documentation states the following: When using a DataSet or DataTable in conjunction with a DataAdapter & a relational data source, use the Delete method of the DataRow to remove...
4
by: lakepeir | last post by:
Hello, I have combobox with a selectedindexchanged method that seems to be called when starting the application, launching the form with the combobox and making a change in the drop down box of...
6
by: mj2736 | last post by:
I created a windows form control that inherits from the standard .Net DataGridView control, to which I've added custom functionality. Instead of using the standard control in my applications, I use...
4
by: Bali | last post by:
Hi I have an ascx control through which I am calling an aspx page using the following command. Page.ClientScript.RegisterStartupScript(GetType(), "test", "window.open(...)"); Initially I...
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...
1
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: 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.