Пример #1
0
 public override async Task ExitAsync(ChromiumProcess p, TimeSpan timeout)
 {
     var waitForExitTask = WaitForExitAsync(p);
     await waitForExitTask.WithTimeout(async() =>
     {
         await Killing.EnterFromAsync(p, this).ConfigureAwait(false);
         await waitForExitTask.ConfigureAwait(false);
     }, timeout).ConfigureAwait(false);
 }
Пример #2
0
 public override async Task ExitAsync(LauncherBase p, TimeSpan timeout)
 {
     var waitForExitTask = WaitForExitAsync(p);
     await waitForExitTask.WithTimeout(
         async() =>
     {
         await Killing.EnterFromAsync(p, this).ConfigureAwait(false);
         await waitForExitTask.ConfigureAwait(false);
     },
         timeout,
         CancellationToken.None).ConfigureAwait(false);
 }
Пример #3
0
                public override async Task ExitAsync(ChromiumProcess p, TimeSpan timeout)
                {
                    var timeoutTask     = Task.Delay(timeout);
                    var waitForExitTask = WaitForExitAsync(p);
                    var completedTask   = await Task.WhenAny(waitForExitTask, timeoutTask).ConfigureAwait(false);

                    if (completedTask == timeoutTask)
                    {
                        await Killing.EnterFromAsync(p, this).ConfigureAwait(false);

                        await waitForExitTask.ConfigureAwait(false);
                    }
                }
Пример #4
0
 public override Task KillAsync(ChromiumProcess p) => Killing.EnterFromAsync(p, this);
Пример #5
0
                private async Task StartCoreAsync(ChromiumProcess p)
                {
                    var output = new StringBuilder();

                    void OnProcessDataReceivedWhileStarting(object sender, DataReceivedEventArgs e)
                    {
                        if (e.Data != null)
                        {
                            output.AppendLine(e.Data);
                            var match = Regex.Match(e.Data, "^DevTools listening on (ws:\\/\\/.*)");
                            if (match.Success)
                            {
                                p._startCompletionSource.TrySetResult(match.Groups[1].Value);
                            }
                        }
                    }

                    void OnProcessExitedWhileStarting(object sender, EventArgs e)
                    => p._startCompletionSource.TrySetException(new ChromiumProcessException($"Failed to launch Chromium! {output}"));
                    void OnProcessExited(object sender, EventArgs e) => Exited.EnterFrom(p, p._currentState);

                    p.Process.ErrorDataReceived += OnProcessDataReceivedWhileStarting;
                    p.Process.Exited            += OnProcessExitedWhileStarting;
                    p.Process.Exited            += OnProcessExited;
                    CancellationTokenSource cts = null;

                    try
                    {
                        p.Process.Start();
                        await Started.EnterFromAsync(p, this).ConfigureAwait(false);

                        p.Process.BeginErrorReadLine();

                        var timeout = p._options.Timeout;
                        if (timeout > 0)
                        {
                            cts = new CancellationTokenSource(timeout);
                            cts.Token.Register(() => p._startCompletionSource.TrySetException(
                                                   new ChromiumProcessException($"Timed out after {timeout} ms while trying to connect to Chromium!")));
                        }

                        try
                        {
                            await p._startCompletionSource.Task.ConfigureAwait(false);

                            await Started.EnterFromAsync(p, this).ConfigureAwait(false);
                        }
                        catch
                        {
                            await Killing.EnterFromAsync(p, this).ConfigureAwait(false);

                            throw;
                        }
                    }
                    finally
                    {
                        cts?.Dispose();
                        p.Process.Exited            -= OnProcessExitedWhileStarting;
                        p.Process.ErrorDataReceived -= OnProcessDataReceivedWhileStarting;
                    }
                }
Пример #6
0
 public override Task KillAsync(LauncherBase p) => Killing.EnterFromAsync(p, this);
Пример #7
0
 public override Task KillAsync(FirefoxProcessManager p) => Killing.EnterFromAsync(p, this);