You can create an event with explicit access:
public event EventHandler TimerElapsed
{
add { timer.Elapsed += value; }
remove { timer.Elapsed -= value; }
}
Clients of your class can subscribe directly to the TimerElapsed event:
appTimer.TimerElapsed += SomeHandlerMethod;
If you want to use the RegisterHandler method, as shown in your code, the parameter type must be EventHandler
EDIT: note that with this approach, the sender parameter value will be a Timer object, not a MyAppTimer object. If this is a problem, you can do it instead:
public MyAppTimer()
{
...
timer.Elapsed += timer_Elapsed;
}
private void timer_Elapsed(object sender, EventArgs e)
{
EventHandler handler = this.TimerElapsed;
if (handler != null)
handler(this, e);
}
source
share