BaconographyPortable.Services.Impl.SuspendableWorkQueueImpl.QueueInteruptableUI C# (CSharp) Method

QueueInteruptableUI() public method

public QueueInteruptableUI ( Task>.Func work ) : void
work Task>.Func
return void
        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);
            }
        }