public void QueueInteruptableUI(Func<CancellationToken, Task> work)
{
bool needsToStartTaskQueue = false;
TaskCompletionSource<bool> completionSource = new TaskCompletionSource<bool>();
lock (_uiInteruptableQueue)
{
_uiInteruptableQueue.Enqueue(work);
if (_uiInteruptableQueue.Count == 1 || !_uiTaskQueueRunning)
{
needsToStartTaskQueue = true;
_uiTaskQueueRunning = true;
}
}
if (needsToStartTaskQueue)
{
_systemServices.StartTimer((timer, arg) =>
{
_systemServices.StopTimer(timer);
RunUIWorkQueue();
}, TimeSpan.FromMilliseconds(0), true);
}
}