コード例 #1
0
        /// <summary>
        /// Async-loop retries for getting the root payload process to await its exit.
        /// </summary>
        private async Task <int?> Init_PayloadProcessMonitoring_WaitForExitCodeAsync()
        {
            for (;;)
            {
                // Might have been terminated on the main thread
                if (_nConsoleProcessExitCode.HasValue)
                {
                    return(null);
                }
                if (_process.HasExited)
                {
                    return(null);
                }

                try
                {
                    // Ask ConEmu for PID
                    GetInfoRoot rootinfo = await GetInfoRoot.QueryAsync(this);

                    // Check if the process has extied, then we're done
                    if (rootinfo.ExitCode.HasValue)
                    {
                        return(rootinfo.ExitCode.Value);
                    }

                    // If it has started already, must get a PID
                    // Await till the process exits and loop to reask conemu for its result
                    // If conemu exits too in this time, then it will republish payload exit code as its own exit code, and implementation will use it
                    if (rootinfo.Pid.HasValue)
                    {
                        await WinApi.Helpers.WaitForProcessExitAsync(rootinfo.Pid.Value);

                        continue;                         // Do not wait before retrying
                    }
                }
                catch (Exception)
                {
                    // Smth failed, wait and retry
                }

                // Await before retrying once more
                await TaskHelpers.Delay(TimeSpan.FromMilliseconds(10));
            }
        }
コード例 #2
0
            private void MoveNext()
            {
                TaskHelpers.Delay(_period, _cts.Token).ContinueWith(
                    (_, thisObject) =>
                {
                    var @this = (PeriodicallyScheduledWorkItem <TState>)thisObject;

                    @this.MoveNext();

                    @this._gate.Wait(
                        @this,
                        closureThis => closureThis._state = closureThis._action(closureThis._state));
                },
                    this,
                    CancellationToken.None,
                    TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion,
                    _taskFactory.Scheduler
                    );
            }
コード例 #3
0
 public async Task WaitAsync(TimeSpan timeout)
 {
     try
     {
         using (var timeoutCancellation = new CancellationTokenSource())
         {
             using (var compositeCancellation = CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellation.Token, cancellation))
             {
                 var timeoutTask = TaskHelpers.Delay(timeout, compositeCancellation.Token);
                 if (timeoutTask == await TaskHelpers.WhenAny(confirmation, timeoutTask).ConfigureAwait(false))
                 {
                     throw new TimeoutException(string.Format("Publisher confirms timed out after {0} seconds waiting for ACK or NACK from sequence number {1}", (int)timeout.TotalSeconds, deliveryTag));
                 }
                 timeoutCancellation.Cancel();
                 await confirmation.ConfigureAwait(false);
             }
         }
     }
     finally
     {
         action();
     }
 }
コード例 #4
0
        private async Task PasteAndSendLinesCommandImpl()
        {
            try
            {
                if (ConsoleService.IsEnabled)
                {
                    string text = ClipboardService.GetText();

                    var lines = Regex.Split(text, $"(?={SettingsService.NewLine})");
                    if (lines.Length > 1)
                    {
                        foreach (var line in lines)
                        {
                            if (!Session.IsRunning)
                            {
                                // The session has ended break the loop.
                                break;
                            }

                            int index = ConsoleService.SelectionStart;
                            await ConsoleService.InsertText(index, line);

                            SerialPortService.Write(line);

                            if (SettingsService.LinePushDelay > 0)
                            {
                                await TaskHelpers.Delay(SettingsService.LinePushDelay);
                            }
                        }
                    }
                }
            }
            catch (ArgumentException e)
            {
                await DialogService.ShowErrorDialogAsync(e.Message, "Exception");
            }
        }
コード例 #5
0
ファイル: TaskPoolScheduler.cs プロジェクト: Scopola/reactive
 private void MoveNext()
 {
     TaskHelpers.Delay(_period, _cts.Token).ContinueWith(