event and delegete

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
 
R

Roger

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top