Ejemplo n.º 1
0
        private async Task FlushAsync()
        {
            (int count, Func <Task>[] actions) = Drain();

            for (int i = 0; i < count; i++)
            {
                await Executor.ExecuteAsync(actions[i]);
            }

            bool lockTaken = false;

            try
            {
                _spinLock.Enter(ref lockTaken);

                if (_queue.Count > 0)
                {
                    _ = _taskFactory.StartNew(_flushCache);
                }
                else
                {
                    _flushPending = false;
                }
            }
            finally
            {
                if (lockTaken)
                {
                    _spinLock.Exit(false);
                }
            }
        }
Ejemplo n.º 2
0
        private async Task FlushAsync()
        {
            (int count, Func <Task>[] actions) = Drain();

            for (int i = 0; i < count; i++)
            {
                Func <Task> action = actions[i];
                await Executor.ExecuteAsync(action);
            }

            lock (_lock)
            {
                if (_queue.Count > 0)
                {
                    _ = _taskFactory.StartNew(_flushCache);
                }
                else
                {
                    _flushPending = false;
                }
            }
        }
Ejemplo n.º 3
0
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
        protected override void InternalEnqueue(Func <Task> action) => Executor.ExecuteAsync(action).Wait();