private void AppUpdate_StateChanged(object sender, IAppUpdateState state) { if (ProgressStarted(state)) { HandleProgressStart(); } else if (ProgressEnded(state)) { HandleProgressEnd(); } _prevState = state; _notifyQueue.Enqueue(() => OnStateChanged(state)); }
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(); }
/// <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(); }); }
/// <summary> /// Writes message to OpenVPN management interface. Safe to call from multiple threads simultaneously. /// </summary> /// <param name="message">Message to write.</param> /// <exception cref="System.IO.IOException">Thrown if failed to write to OpenVPN management socket.</exception> public Task WriteLine(string message) { return(_writeQueue.Enqueue(() => _managementChannel.WriteLine(message))); }