I am using this code but I get the following error when calling the Tick method: Use of unassigned local variable.
try
{
//Something
}catch (Exception e)
{
int sec = 120000; // 2 minutes
int period = 5000; //every 5 seconds
TimerCallback timerDelegate = new TimerCallback(Tick);
System.Threading.Timer _dispatcherTimer = new System.Threading.Timer(timerDelegate, null, period, period);// if you want the method to execute immediately,you could set the third parameter to null
void Tick(object state)
{
Device.BeginInvokeOnMainThread(() =>
{
sec -= period;
if (sec >= 0)
{
//do something
}
else
{
_dispatcherTimer.Dispose();
}
});
}
}
The error occurs when in the else clause I put _dispatcherTimer.Dispose();
but how can I make it work without deleting this line?