I'm trying to raise and handle an event. I'm using an example from the
VS.NET help files
(http://msdn.microsoft.com/library/de...-us/cpguide/ht
ml/cpconprovidingeventfunctionality.asp)
Near the bottom is the code below. Two questions:
1. Why does it check to see if Alarm doesn't equal null?
2. Whenever I use my debugger to walk through the OnAlarm method, Alarm
always equals null so the Alarm(this, e) method is never called ... why
would this be?
Thanks in advance!
Mark
public class AlarmClock
{
//Step 3. The Alarm event is defined using the event keyword.
//The type of Alarm is AlarmEventHandler.
public event AlarmEventHandler Alarm;
//Step 4. The protected OnAlarm method raises the event by invoking
//the delegates. The sender is always this, the current instance of
//the class.
protected virtual void OnAlarm(AlarmEventArgs e)
{
if (Alarm != null)
{
//Invokes the delegates.
Alarm(this, e);
}
}
}