473,782 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2188
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.co m

"Ivan" <iv*********@dy namic-imaging.com> wrote in message
news:e5******** ******@tk2msftn gp13.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
2653
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 deciding how to respond. Does anyone know if this is possible.
0
1312
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 MyEventHandler myEventHandler; you can subscribe to the event, using the construction myEventHandler += subscriber; but you cannot do the same by sending event handler as a parameter to a method of the same class.
3
1600
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 file. Is this possible? /Casper
1
4238
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 the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
25
29763
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" name="ClickedElement" id="Messenger" /> </form> </body>
5
3112
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 the row. The Delete method marks the row as Deleted in the DataSet or DataTable but does not remove it. Instead when the DataAdapter encounters a row marked as Deleted, it executes its DeleteCommand method to delete the row at the data source. The...
4
5257
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 the combobox. Can anyone tell me why the method is called so often? I would only like the method executed when a user makes a change in the drop down box. Am I using the incorrect method. Thanks.
6
6102
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 my customized version. I have an event handler in the custom control for the KeyDown event that simulates a double-click on the selected grid row when the user presses the enter key. This is working just fine. Now, some screens that are using...
4
2024
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 just added a label controls on the page and it opened up fine without any errors.
0
10146
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...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9942
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
8967
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...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
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...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
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
2874
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.