I have a class that uses a timer. A start method, to configure the timer and start it. And a Stop timer to dispose the timer. The code is this:
Start()
{
_timer = new Timer(MyHandler, null, 0, 1000);
}
Stop()
{
_timer.Dispose();
}
async void MyHandler()
{
try
{
//Do something.
await myAsyncMethd();
}
catch
{
Stop();
}
}
The problem is that if some exception is catch in the handler, when it stop, the code of the handler still runs few more times until finally it stops.
I am wondering if this is normal because it is a code that it is run in another thread or there would be some way to stop immediately onece the exception is catched.
Thanks.