public void RunTaskInSerial() { // 큐에 추가된 Task 순서대로 실행되는지 검사한다. var taskQueue = new SerialTaskQueue(); int count = 0; for(int i = 0; i < TaskCount; i++) { var task = new Task(state => { Thread.Sleep(Rnd.Next(10, 50)); if(IsDebugEnabled) log.Debug("index = " + state); Assert.AreEqual(count, (int)state); Interlocked.Increment(ref count); }, i); taskQueue.Enqueue(task); } // 큐에 있는 모든 Task들이 실행될 때까지 기다립니다. // taskQueue.Completed().Wait(); }
public ExtendedProgressAppUpdate(TimeSpan minProgressDuration, INotifyingAppUpdate origin) { _minProgressDuration = minProgressDuration; _origin = origin; _origin.StateChanged += AppUpdate_StateChanged; _notifyQueue = new SerialTaskQueue(); }
public void Test_CoordinationDataStructures_SerialTaskQueue() { //模式:放入队列中的任务串联执行 var q = new SerialTaskQueue(); q.Enqueue(() => Task.Factory.StartNew(() => "1")); q.Enqueue(() => Task.Factory.StartNew(() => "2")); var isCompleted = q.Completed().IsCompleted; Assert.IsTrue(isCompleted); }
/// <summary> /// <paramref name="actions"/>를 <paramref name="count"/> 수 만큼 순서대로 수행합니다. /// </summary> /// <param name="count"></param> /// <param name="actions"></param> /// <seealso cref="SerialTaskQueue"/> public static void RunTaskQueue(int count, params Action[] actions) { Parallel.For(0, count, i => { var serialTaskQueue = new SerialTaskQueue(); foreach(var @action in actions) { var @localAction = @action; serialTaskQueue.Enqueue(new Task(@localAction)); } serialTaskQueue.Completed().Wait(); }); }
/// <summary> /// <paramref name="actions"/>를 <paramref name="count"/> 수 만큼 순서대로 수행합니다. /// </summary> /// <param name="count"></param> /// <param name="actions"></param> /// <seealso cref="SerialTaskQueue"/> public static void RunTaskQueue(int count, params Action[] actions) { Parallel.For(0, count, i => { var serialTaskQueue = new SerialTaskQueue(); foreach (var @action in actions) { var @localAction = @action; serialTaskQueue.Enqueue(new Task(@localAction)); } serialTaskQueue.Completed().Wait(); }); }
public ConcurrentManagementChannel(IManagementChannel managementChannel) { _managementChannel = managementChannel; _writeQueue = new SerialTaskQueue(); }