Yes, I don’t know what I am doing…
From ProgramOne.cs, what is the proper way to remove/stop further events from ProgramTwo.cs
I tried Delegate.Remove but I could not determine the correct syntax to use.
(Not really sure if Delegate.Remove is even intended for what I want to do.)
At some point in ProgramOne I want to stop receiving events from Program2 (not just ignore them) and at some point potentiality resume events.
Scenario:
ProgramOne.cs
namespace A
classA
Closed += new ClosedEventHandler(Closed);
void Closed()
{
//Do something when event received
}
// End
/*-----------------------------------------------------------------------------*/
ProgramTwo.cs
namespace B
classB
public delegate void ClosedEventHandler();
public static event ClosedEventHandler Closed;
// On event
protected virtual void OnClose()
{
// I can prevent further events from occurring by using this..
// There must be a better (proper) way.
if (Closed != null)
{
Closed();
}
if (Closed != null)
{
// Prevent further events
Closed -= Closed;
}
}
protected override void OnDoingSomething( )
{
........
........
OnClose();
}
// End