Exemplo n.º 1
0
        public void Dequeue()
        {
            if (_animationRunning == 0)
            {
                throw new ArgumentException();
            }

            _animationRunning--;
            if (_animationRunning == 0)
            {
                QueueEmptied?.Invoke();
            }
        }
Exemplo n.º 2
0
        private async void StartWorkLoopIfNeeded()
        {
            if (_running)
            {
                return;
            }

            try
            {
                _running = true;
                while (_workQueue.Count > 0)
                {
                    var workItemInfo = _workQueue.Dequeue();

                    if (workItemInfo.CancellationToken.IsCancellationRequested)
                    {
                        workItemInfo.CompletionSource.SetCanceled();
                    }
                    else
                    {
                        //RnLog.Info($"UI AwaitingQueue: Start {currentName}");
                        try
                        {
                            var result = await workItemInfo.WorkItem();

                            workItemInfo.CompletionSource.SetResult(result);
                        }
                        catch (Exception ex)
                        {
                            workItemInfo.CompletionSource.SetException(ex);
                        }
                        //RnLog.Info($"UI AwaitingQueue: End {currentName}");
                    }
                }
                _running = false; // Ensure _running is updated before firing the event
                QueueEmptied?.Invoke(this, null);
            }
            finally
            {
                // Before exiting this method, ensure _running is updated
                _running = false;
            }
        }