public object StartTimer(EventHandler<object> tickHandler, TimeSpan tickSpan, bool uiThread)
{
if (uiThread)
{
if (tickSpan.Ticks == 0)
{
_uiDispatcher.BeginInvoke(() => tickHandler(null, null));
return null;
}
else
{
TaskCompletionSource<DispatcherTimer> completionSource = new TaskCompletionSource<DispatcherTimer>();
_uiDispatcher.BeginInvoke(() =>
{
DispatcherTimer dt = new DispatcherTimer();
dt.Tick += (sender, args) => tickHandler(sender, args);
dt.Interval = tickSpan;
dt.Start();
completionSource.SetResult(dt);
});
return completionSource.Task;
}
}
else
{
return ThreadPoolTimer.CreatePeriodicTimer((timer) => tickHandler(this, timer), tickSpan);
}
}