event and delegete

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi!

Is it possible to rewrite this code in such a way
that I get something like
event AlarmEventHandler myEvent;
I'm not so used to code when it is written in this way.

//Here is the Code
If AlarmEventArgs e = new AlarmEventArgs(1,2);
AlarmEventHandler handler = Alarm;

if (handler != null)
{
handler(this, e);
}

//Tony
 
public event AlarmEventHandler myEvent;

The subscriber should:
myEvent += MyHandler;

Then the publisher should call it when appropriate:
if (myEvent != null)
{
AlarmEventArgs e = new AlarmEventArgs(1,2);
myEevent(this, e);
}

I think this is about it, not tested though.
Roger
 
Back
Top