Beispiel #1
0
        public async Task Do_not_run_task_before_previous_completion()
        {
            // arrange
            var done = false;

            var slowTaskSource = new TaskCompletionSource <bool>();

            Task SlowAsync(CancellationToken token) => slowTaskSource.Task;

            Task DoneAsync(CancellationToken token)
            {
                done = true;
                return(Task.CompletedTask);
            }

            // act
            using (var tasks = new TaskQueue(_logger))
            {
                _ = tasks.Enqueue(SlowAsync);
                var doneTask = tasks.Enqueue(DoneAsync);
                // assert
                await Task.Delay(100);

                done.Should().BeFalse();
                slowTaskSource.SetResult(true);
                await slowTaskSource.Task;
                await doneTask;
                done.Should().BeTrue();
                await tasks.DrainOutAsync();
            }
        }
        private void KeepAlive(object state)
        {
            if (_connections.IsEmpty && _connections.Count == 0)
            {
                return;
            }

            _taskQueue.Enqueue(async() => {
                var sockets     = GetAll();
                var openSockets = sockets.Where(s => s.State == WebSocketState.Open).ToArray();
                if (_logger.IsEnabled(LogLevel.Trace))
                {
                    _logger.LogTrace("Sending web socket keep alive to {OpenSocketsCount} open connections of {SocketCount} total connections", openSockets.Length, sockets.Count);
                }

                foreach (var socket in openSockets)
                {
                    try {
                        await socket.SendAsync(buffer: _keepAliveMessage,
                                               messageType: WebSocketMessageType.Text,
                                               endOfMessage: true,
                                               cancellationToken: CancellationToken.None);
                    } catch (WebSocketException ex) when(ex.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely)
                    {
                        // NOTE: This will not remove it from the ConnectionMappings.
                        await RemoveWebSocketAsync(socket);
                    } catch (Exception ex) {
                        _logger.LogError(ex, "Error sending keep alive socket message: {Message}", ex.Message);
                    }
                }
            });
        }
        public void TaskQueueMaxSizeTest()
        {
            var depth = 10;
            var taskQueue = new TaskQueue();
            taskQueue.SetMaxQueueSize(depth);
            var wait = true;
            for (var i = 0; i < depth; i++)
            {
                taskQueue.Enqueue(t => Task.Run(() =>
                {
                    while (wait)
                        Thread.Sleep(5);
                }), wait);
            }

            taskQueue.Size.Should().Be(depth);
            var newItem = taskQueue.Enqueue(t => Task.FromResult(0), wait);
            newItem.Should().BeNull("This should exceed the max and return a null task since it was not enqueued");
            taskQueue.Size.Should().Be(depth);
            
            wait = false;
            Thread.Sleep(25);
            newItem = taskQueue.Enqueue(t => Task.FromResult(0), wait);
            newItem.Should().NotBeNull("Released the queue and it should have space again");
        }
Beispiel #4
0
        public void CanRunContinuously()
        {
            Log.MinimumLevel = LogLevel.Trace;

            int completed = 0;
            var countdown = new CountdownEvent(1);

            using (var queue = new TaskQueue(queueEmptyAction: () => {
                if (completed > 2)
                {
                    countdown.Signal();
                }
            }, loggerFactory: Log)) {
                queue.Enqueue(() => { Interlocked.Increment(ref completed); return(Task.CompletedTask); });
                queue.Enqueue(() => { Interlocked.Increment(ref completed); return(Task.CompletedTask); });
                queue.Enqueue(() => { Interlocked.Increment(ref completed); return(Task.CompletedTask); });
                Assert.InRange(queue.Queued, 1, 3);

                countdown.Wait(TimeSpan.FromSeconds(2));
                Assert.Equal(0, countdown.CurrentCount);
                Assert.Equal(0, queue.Queued);
                Assert.Equal(0, queue.Working);
                Assert.Equal(3, completed);
            }
        }
Beispiel #5
0
        public void CanRunContinuously()
        {
            int completed = 0;
            var countdown = new CountdownEvent(1);

            using (var queue = new TaskQueue())
            {
                queue.WaitWhenEmpty.ContinueWith(t =>
                {
                    if (completed > 2)
                    {
                        countdown.Signal();
                    }
                });

                queue.Enqueue(() => { Interlocked.Increment(ref completed); return(Task.CompletedTask); });
                queue.Enqueue(() => { Interlocked.Increment(ref completed); return(Task.CompletedTask); });
                queue.Enqueue(() => { Interlocked.Increment(ref completed); return(Task.CompletedTask); });
                //Assert.InRange(queue.Queued, 1, 3);

                countdown.Wait(TimeSpan.FromSeconds(2));
                Assert.AreEqual(0, countdown.CurrentCount);
                Assert.AreEqual(0, queue.Queued);
                Assert.AreEqual(0, queue.Working);
                Assert.AreEqual(3, completed);
            }
        }
        public void TaskQueueMaxSizeTest()
        {
            var depth     = 10;
            var taskQueue = new TaskQueue();

            taskQueue.SetMaxQueueSize(depth);
            var wait = true;

            for (var i = 0; i < depth; i++)
            {
                taskQueue.Enqueue(t => Task.Run(() => {
                    while (wait)
                    {
                        Thread.Sleep(5);
                    }
                }), wait);
            }

            taskQueue.Size.Should().Be(depth);
            var newItem = taskQueue.Enqueue(t => Task.FromResult(0), wait);

            newItem.Should().BeNull("This should exceed the max and return a null task since it was not enqueued");
            taskQueue.Size.Should().Be(depth);

            wait = false;
            Thread.Sleep(25);
            newItem = taskQueue.Enqueue(t => Task.FromResult(0), wait);
            newItem.Should().NotBeNull("Released the queue and it should have space again");
        }
        public Task <ParseConfig> GetCurrentConfigAsync()
        {
            return(taskQueue.Enqueue(toAwait => toAwait.ContinueWith(_ =>
            {
                if (currentConfig == null)
                {
                    return storageController.LoadAsync().OnSuccess(t =>
                    {
                        object tmp;
                        t.Result.TryGetValue(CurrentConfigKey, out tmp);

                        string propertiesString = tmp as string;
                        if (propertiesString != null)
                        {
                            var dictionary = ParseClient.DeserializeJsonString(propertiesString);
                            currentConfig = new ParseConfig(dictionary);
                        }
                        else
                        {
                            currentConfig = new ParseConfig();
                        }

                        return currentConfig;
                    });
                }

                return Task.FromResult(currentConfig);
            }), CancellationToken.None).Unwrap());
        }
 private async void FtpServer_SentData(object sender, FtpSentDataEventArgs e)
 {
     IUpgradeTasksModel upgradeTaskDataModel = ServiceLocator.Current.GetInstance <IUpgradeTasksModel>();
     await _upgradeTaskQueue.Enqueue(() => Task.Run(() =>
     {
         //var task = upgradeTaskDataModel.Select(
         var task = upgradeTaskDataModel.Data.Where(
             t => t.Status == UpgradeStatus.InProgress &&
             t.Device.ip == e.Remote.Address.ToString()
             //t => t.Device
             ).FirstOrDefault();
         if (task != null)
         {
             task.LastUpdateTime = DateTime.Now;
             task.SentDataBytes  = e.SentBytes;
             try
             {
                 upgradeTaskDataModel.UpdateAsync(
                     task,
                     t => t.SentDataBytes,
                     t => t.LastUpdateTime).Wait();
                 //DebugLog.TraceMessage(string.Format("Sent({0}) Total({1}) - {2} %)", e.SentBytes, e.FileSize, e.SentBytes * 100 / e.FileSize));
             }
             catch (Exception) { }
         }
     }
                                                    ));
 }
        public void TaskQueueDrainTest()
        {
            var depth     = 10;
            var taskQueue = new TaskQueue();

            taskQueue.SetMaxQueueSize(depth);
            var wait = true;

            for (var i = 0; i < depth; i++)
            {
                taskQueue.Enqueue(t => Task.Run(() => {
                    while (wait)
                    {
                        Thread.Sleep(10);
                    }
                }), wait);
            }

            wait = false;
            taskQueue.Drain();
            taskQueue.Size.Should().Be(0);

            var newItem = taskQueue.Enqueue(t => Task.FromResult(0), wait);

            newItem.Should().NotBeNull();
        }
Beispiel #10
0
        public Task MoveUpAsync(advertisement obj)
        {
            return(Task.Run(async() =>
            {
                advertisement currentItem = obj;
                advertisement previousItem;

                lock (_lock)
                {
                    int currentIndex = _data.IndexOf(currentItem);
                    if (currentIndex == 0)
                    {
                        return;
                    }
                    previousItem = _data[currentIndex - 1];
                    int?tmp = currentItem.C_no;
                    currentItem.C_no = previousItem.C_no;
                    previousItem.C_no = tmp;

                    _data[currentIndex - 1] = currentItem;
                    _data[currentIndex] = previousItem;
                }

                List <advertisement> objs = new List <advertisement>();
                objs.Add(currentItem);
                objs.Add(previousItem);
                await updateTasks.Enqueue(() => _dataService.UpdateAsync(objs));
                //await updateTasks.Enqueue(() => _dataService.UpdateAsync(currentItem)).ConfigureAwait(false);
                //await updateTasks.Enqueue(() => _dataService.UpdateAsync(previousItem)).ConfigureAwait(false);
            }));
        }
Beispiel #11
0
        public void ExceptionTest()
        {
            var queue = new TaskQueue();

            AssertThrow<ArgumentNullException>(
                () => queue.Enqueue(null),
                () => queue.Enqueue((Func<Task<string>>)null));
        }
Beispiel #12
0
 private async Task Perform(MapDocumentOperation operation)
 {
     await _queue.Enqueue(async() =>
     {
         var change = await operation.Operation.Perform(operation.Document);
         await SendChange(change);
     });
 }
Beispiel #13
0
        public async Task DrainingTaskQueueShutsQueueOff()
        {
            var queue = new TaskQueue();
            await queue.Enqueue(() => Task.CompletedTask);

            await queue.Drain();

            // This would throw if the task was queued successfully
            await queue.Enqueue(() => Task.FromException(new Exception()));
        }
Beispiel #14
0
        public void FailedToEnqueueReturnsNull()
        {
            var queue = new TaskQueue(TaskAsyncHelper.Empty, 2);

            queue.Enqueue(() => Task.Delay(100));
            queue.Enqueue(() => Task.Delay(100));
            Task task = queue.Enqueue(() => Task.Delay(100));

            Assert.Null(task);
        }
Beispiel #15
0
        public void TaskQueueDoesNotQueueNewTasksIfPreviousTaskFaulted()
        {
            var queue = new TaskQueue();

            queue.Enqueue(() => TaskAsyncHelper.FromError(new Exception()));
            Task task = queue.Enqueue(() => TaskAsyncHelper.Empty);

            Assert.True(task.IsCompleted);
            Assert.True(task.IsFaulted);
        }
 private void BtnDelete_Click(object sender, RoutedEventArgs e)
 {
     if (_selectCharacterInfo != null)
     {
         _includeNicknames.Remove(_selectCharacterInfo.Nickname);
         this._characterList.Remove(this._selectCharacterInfo);
         _taskQueue.Enqueue(FileSave);
         Clear();
     }
 }
Beispiel #17
0
 /// <summary>
 /// Saves the file to the LeanCloud cloud.
 /// </summary>
 /// <param name="progress">The progress callback.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 public Task SaveAsync(IProgress <AVUploadProgressEventArgs> progress,
                       CancellationToken cancellationToken)
 {
     return(taskQueue.Enqueue(
                toAwait => FileController.SaveAsync(state, dataStream, AVUser.CurrentSessionToken, progress, cancellationToken), cancellationToken)
            .OnSuccess(t =>
     {
         state = t.Result;
     }));
 }
Beispiel #18
0
        public void NotifiesMonitorWhenMultipleTasksStartsAndCompletes()
        {
            var mockMonitor = new Mock <ITaskMonitor>();
            var queue       = new TaskQueue(TaskAsyncHelper.Empty, mockMonitor.Object);

            queue.Enqueue(() => TaskAsyncHelper.Empty);
            queue.Enqueue(() => TaskAsyncHelper.Empty);

            mockMonitor.Verify(m => m.TaskStarted(), Times.Exactly(2));
            mockMonitor.Verify(m => m.TaskCompleted(), Times.Exactly(2));
        }
Beispiel #19
0
    public Task <T> Enqueue <T>(Func <Task <T> > taskGenerator)
    {
        TaskCompletionSource <T> tcs = new TaskCompletionSource <T>();
        var unused = queue.Enqueue(() =>
        {
            tcs.Match(taskGenerator());
            return(Task.Delay(TimeSpan.FromSeconds(1)));
        });

        return(tcs.Task);
    }
Beispiel #20
0
        public void DrainingTaskQueueShutsQueueOff()
        {
            var queue = new TaskQueue();

            queue.Enqueue(() => TaskAsyncHelper.Empty);
            queue.Drain();
            Task task = queue.Enqueue(() => TaskAsyncHelper.FromError(new Exception()));

            Assert.True(task.IsCompleted);
            Assert.False(task.IsFaulted);
        }
Beispiel #21
0
        public void CanRespectMaxItems()
        {
            using (var queue = new TaskQueue(maxItems: 1, autoStart: false))
            {
                queue.Enqueue(() => Task.CompletedTask);
                queue.Enqueue(() => Task.CompletedTask);

                Assert.AreEqual(1, queue.Queued);
                Assert.AreEqual(0, queue.Working);
            }
        }
Beispiel #22
0
        public async Task TaskQueueDoesNotQueueNewTasksIfPreviousTaskFaulted()
        {
            var exception = new Exception();
            var queue     = new TaskQueue();
            var ignore    = queue.Enqueue(() => Task.FromException(exception));
            var task      = queue.Enqueue(() => Task.CompletedTask);

            var actual = await Assert.ThrowsAsync <Exception>(async() => await task);

            Assert.Same(exception, actual);
        }
Beispiel #23
0
        public void CanRespectMaxItems()
        {
            Log.MinimumLevel = LogLevel.Trace;

            using (var queue = new TaskQueue(maxItems: 1, autoStart: false, loggerFactory: Log)) {
                queue.Enqueue(() => Task.CompletedTask);
                queue.Enqueue(() => Task.CompletedTask);

                Assert.Equal(1, queue.Queued);
                Assert.Equal(0, queue.Working);
            }
        }
Beispiel #24
0
        public async Task TestCancellationTokenCancelled()
        {
            // Arrange
            var n         = 0;
            var taskQueue = new TaskQueue(2);

            taskQueue.Enqueue(async() =>
            {
                await Task.Delay(40);
                n++;
            });
            taskQueue.Enqueue(async() =>
            {
                await Task.Delay(50);
                n++;
            });

            taskQueue.Enqueue(async() =>
            {
                await Task.Delay(60);
                n++;
            });
            taskQueue.Enqueue(async() =>
            {
                await Task.Delay(70);
                n++;
            });
            var cancellationTokenSource = new CancellationTokenSource();

            // Act & Assert

            var t = taskQueue.WhenAll(cancellationTokenSource.Token);

            await Task.Delay(10);

            Assert.Equal(2, taskQueue.Waiting);
            Assert.Equal(2, taskQueue.Executing);
            Assert.Equal(0, taskQueue.Completed);

            cancellationTokenSource.Cancel();

            await t;

            Assert.True(cancellationTokenSource.IsCancellationRequested);
            Assert.True(t.IsCompleted);
            Assert.Equal(2, taskQueue.Waiting);
            Assert.Equal(2, taskQueue.Executing);
            Assert.Equal(0, taskQueue.Completed);
            Assert.Equal(0, n);
        }
Beispiel #25
0
        public void CanRunAndWait()
        {
            int completed = 0;
            var countdown = new CountdownEvent(1);

            using (var queue = new TaskQueue(autoStart: false))
            {
                void Sub(int id)
                {
                    queue.WaitWhenEmpty.ContinueWith(t =>
                    {
                        if (queue.WaitWhenEmpty.Id != id)
                        {
                            Sub(queue.WaitWhenEmpty.Id);
                        }

                        return(countdown.Signal());
                    });
                }

                Sub(queue.WaitWhenEmpty.Id);

                queue.Enqueue(() => {
                    Interlocked.Increment(ref completed);
                    return(Task.CompletedTask);
                });

                Assert.AreEqual(1, queue.Queued);
                queue.Start();

                countdown.Wait(TimeSpan.FromSeconds(2));
                Assert.AreEqual(0, countdown.CurrentCount);
                Assert.AreEqual(0, queue.Queued);
                Assert.AreEqual(1, completed);

                Thread.Sleep(30);
                countdown.Reset();

                queue.Enqueue(() => {
                    Interlocked.Increment(ref completed);
                    return(Task.CompletedTask);
                });

                countdown.Wait(TimeSpan.FromSeconds(2));
                Assert.AreEqual(0, countdown.CurrentCount);
                Assert.AreEqual(0, queue.Queued);
                Assert.AreEqual(2, completed);
            }
        }
        public void Start()
        {
            if (IsRunning)
            {
                return;
            }

            //var looper = ServiceProvider.GetRequiredService<LoopingTyperRunner>();
            //var patternRepeater = new PatternRepeater();
            var patternRepeater = new ComplexPatternRepeater();
            var soundService    = new SoundService();
            var backgroundTask  = new BackgroundTaskRunner(async ct =>
            {
                soundService.Play(SoundServiceSound.Start);
                await patternRepeater.RunAsync(ct);
                soundService.Play(SoundServiceSound.End);
                return(true);
            });

            TaskQueue.Enqueue(backgroundTask);

            if (!IsRunning)
            {
                DoDequeueLoop().GetAwaiter();
            }
        }
        private void OnMessage(string key, byte[] data)
        {
            // The key is the stream id (channel)
            var message = RedisMessage.Deserialize(data);

            _publishQueue.Enqueue(() => OnReceived(key, (ulong)message.Id, message.Messages));
        }
Beispiel #28
0
        public void CanProcessInParrallelQuicklyWithRandomDelays()
        {
            const int NumberOfEnqueuedItems  = 500;
            const int MaxDelayInMilliseconds = 10;
            const int MaxDegreeOfParallelism = 4;

            int completed = 0;
            var countdown = new CountdownEvent(1);

            using (var queue = new TaskQueue(maxDegreeOfParallelism: MaxDegreeOfParallelism, autoStart: false))
            {
                queue.WaitWhenEmpty.ContinueWith(t => countdown.Signal());

                for (int i = 0; i < NumberOfEnqueuedItems; i++)
                {
                    queue.Enqueue(async() => {
                        var delay = TimeSpan.FromMilliseconds(new Random().Next(0, MaxDelayInMilliseconds));
                        await Task.Delay(delay);
                        Interlocked.Increment(ref completed);
                    });
                }

                Assert.AreEqual(NumberOfEnqueuedItems, queue.Queued);

                var sw = Stopwatch.StartNew();
                queue.Start();

                countdown.Wait(TimeSpan.FromSeconds(NumberOfEnqueuedItems * MaxDelayInMilliseconds));
                Assert.AreEqual(0, countdown.CurrentCount);
                Assert.AreEqual(0, queue.Queued);
                Assert.AreEqual(0, queue.Working);
                Assert.AreEqual(NumberOfEnqueuedItems, completed);
            }
        }
Beispiel #29
0
        public void CanProcessInParrallelQuickly()
        {
            const int NumberOfEnqueuedItems  = 1000;
            const int MaxDegreeOfParallelism = 2;

            int completed = 0;
            var countdown = new CountdownEvent(1);

            using (var queue = new TaskQueue(maxDegreeOfParallelism: MaxDegreeOfParallelism, autoStart: false))
            {
                queue.WaitWhenEmpty.ContinueWith(t => countdown.Signal());

                for (int i = 0; i < NumberOfEnqueuedItems; i++)
                {
                    queue.Enqueue(() => {
                        Interlocked.Increment(ref completed);
                        return(Task.CompletedTask);
                    });
                }

                Assert.AreEqual(NumberOfEnqueuedItems, queue.Queued);

                var sw = Stopwatch.StartNew();
                queue.Start();

                countdown.Wait(TimeSpan.FromSeconds(5));
                //Assert.InRange(countdown.CurrentCount, -1, 0); // TODO: There is a possibility where on completed could be called twice.
                Assert.AreEqual(0, queue.Queued);
                Assert.AreEqual(0, queue.Working);
                Assert.AreEqual(NumberOfEnqueuedItems, completed);
            }
        }
Beispiel #30
0
        public void CanProcessQuickly()
        {
            const int NumberOfEnqueuedItems = 1000;

            int completed = 0;
            var countdown = new CountdownEvent(1);

            using (var queue = new TaskQueue(autoStart: false))
            {
                queue.WaitWhenEmpty.ContinueWith(t => countdown.Signal());

                for (int i = 0; i < NumberOfEnqueuedItems; i++)
                {
                    queue.Enqueue(() => {
                        Interlocked.Increment(ref completed);
                        return(Task.CompletedTask);
                    });
                }

                Assert.AreEqual(NumberOfEnqueuedItems, queue.Queued);
                var sw = Stopwatch.StartNew();
                queue.Start();

                countdown.Wait(TimeSpan.FromSeconds(5));
                Assert.AreEqual(0, countdown.CurrentCount);
                Assert.AreEqual(0, queue.Queued);
                Assert.AreEqual(0, queue.Working);
                Assert.AreEqual(NumberOfEnqueuedItems, completed);
            }
        }
Beispiel #31
0
        async Task IGangMember.HandleAsync(GangMessageTypes type, byte[] data, GangAudit audit)
        {
            await _sendQueue.Enqueue(async() =>
            {
                try
                {
                    await _webSocket.SendAsync(
                        new[] { (byte)type },
                        WebSocketMessageType.Binary, data == null, CancellationToken.None);

                    if (audit?.Version != null)
                    {
                        await _webSocket.SendAsync(
                            BitConverter.GetBytes(audit.Version.Value),
                            WebSocketMessageType.Binary, data == null, CancellationToken.None);
                    }

                    if (data != null)
                    {
                        await _webSocket.SendAsync(
                            data,
                            WebSocketMessageType.Binary, true, CancellationToken.None);
                    }
                }
                catch (WebSocketException)
                {
                    // ignore this
                }
            });
        }
Beispiel #32
0
        public void Reset(WaypointTask holdTask, WaypointTask approachTask, WaypointTask enterTask, WaypointTask closeTask, DockTask dockTask, MyTuple <IntelItemType, long> intelKey, MyGridProgram program, MyCubeSize dockSize, IMyTerminalBlock connector, IMyTerminalBlock indicator = null)
        {
            Reset();
            if (indicator != null)
            {
                Indicator = indicator;
                Connector = connector;
            }
            EnterHoldingPattern = holdTask;
            WaitForClearance    = new WaitTask();
            ApproachEntrance    = approachTask;
            ApproachDock        = enterTask;
            FinalAdjustToDock   = closeTask;
            DockTask            = dockTask;
            IntelKey            = intelKey;
            DockSize            = dockSize;
            Program             = program;

            closeTask.Destination.MaxSpeed = 0.5f;
            enterTask.Destination.MaxSpeed = 5;

            TaskQueue.Enqueue(EnterHoldingPattern);
            TaskQueue.Enqueue(WaitForClearance);
            TaskQueue.Enqueue(ApproachEntrance);
            TaskQueue.Enqueue(ApproachDock);
            TaskQueue.Enqueue(FinalAdjustToDock);
            TaskQueue.Enqueue(DockTask);
        }
Beispiel #33
0
 public void MainTest()
 {
     AsyncPump.Run(
         async () =>
         {
             var counter = 0;
             var queue = new TaskQueue();
             queue.Enqueue(
                 async () =>
                 {
                     await Task.Delay(250);
                     ++counter;
                 }).Ignore();
             Assert.AreEqual(2, await queue.Enqueue(() => Task.FromResult(++counter)));
             Assert.AreEqual(2, counter);
         });
 }
        public void TaskQueueDrainTest()
        {
            var depth = 10;
            var taskQueue = new TaskQueue();
            taskQueue.SetMaxQueueSize(depth);
            var wait = true;
            for (var i = 0; i < depth; i++)
            {
                taskQueue.Enqueue(t => Task.Run(() =>
                {
                    while (wait)
                        Thread.Sleep(10);
                }), wait);
            }

            wait = false;
            taskQueue.Drain();
            taskQueue.Size.Should().Be(0);

            var newItem = taskQueue.Enqueue(t => Task.FromResult(0), wait);
            newItem.Should().NotBeNull();
        }
        public void TaskQueueSizeTest()
        {
            var depth = 10;
            var taskQueue = new TaskQueue();
            var wait = true;
            for (var i = 0; i < depth; i++)
            {
                taskQueue.Enqueue(t => Task.Run(() =>
                {
                    while(wait)
                        Thread.Sleep(5);
                }), wait);
            }

            taskQueue.Size.Should().Be(depth);
            wait = false;
            Thread.Sleep(25);
            taskQueue.Size.Should().Be(0);
        }
Beispiel #36
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="taskCollection"></param>
        private void DoTasks(TaskQueue tasks)
        {
            if (tasks.Count == 0)
            {
                return;
            }

            TaskCollection tempTasks = new TaskCollection();

            while (tasks.Count > 0)
            {
                ITask headTask = tasks.Dequeue();

                bool b = DoNotExecutingTask(headTask);
                if (b)
                {
                    break;
                }
                else
                {
                    tempTasks.Add(headTask);
                }
            }

            //
            //
            tasks.Enqueue(tempTasks);
        }