controlButton.Click += new System.EventHandler(this.controlButton_StopClick);
how can i check if Click has not already been wired with a method in order to avoid multiple invoking of controlButton_StopClick ?
------------------------
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
controlButton.Click += new System.EventHandler(this.controlButton_StopClick);
private bool bAlreadyset = false;
public event EventHandler Click
{
add
{
lock (this)
{
if (!bAlreadyset)
{
this.Click += value;
bAlreadyset = true;
}
else
{
//throw an exception if you need to
}
}
}
remove
{
lock (this)
{
this.Click -= value;
bAlreadyset = false;
}
}
}
// The delegate (method signature) that event handlers must follow
public delegate void ChangedEventDelegate(object sender, EventArgs e);
// The event that people will subscribe to
public event ChangedEventDelegate ChangedEvent;
protected void FireChangedEvent(MyEventArgs e)
{
if (this.ChangedEvent != null)
{
foreach(ChangedEventDelegate d in this.ChangedEvent.GetInvocationList())
{
try
{
d(this, e);
}
catch
{
// Do nothing, as the subscribers are responsible
// for handling exceptions in their handlers. We
// just have this try..catch here as a safety net
// in case someone forgets. It will allow us to
// proceed to the next invocation target.
// But we might want to log it anyway, so we can
// smack the developer who forgot their try block
}
}
}
ArrayList arInvocationList = new ArrayList();
public [b]new[/b] event EventHandler Click
{
add
{
lock (this)
{
if ( !arInvocationList.Contains( value))
{
this.Click += value;
}
else
{
//throw an exception if you need to
}
}
}
remove
{
lock (this)
{
this.Click -= value;
arInvocationList.Remove( value);
}
}
}
No it doesn't. If a developer registeres for a callback twice, that's another situation where a smack is called-for.by the way - chip: how does this ensure that the handler is called only once? from what i see what you've posted calls each registered handler as many times as it's been added