Beispiel #1
0
        private async Task CloseCoreAsync()
        {
            try
            {
                try
                {
                    // Initiate graceful browser close operation but don't await it just yet,
                    // because we want to ensure chromium process shutdown first.
                    var browserCloseTask = Connection.IsClosed
                        ? Task.CompletedTask
                        : Connection.SendAsync("Browser.close", null);

                    if (ChromiumProcess != null)
                    {
                        // Notify chromium process that exit is expected, but should be enforced if it
                        // doesn't occur withing the close timeout.
                        var closeTimeout = TimeSpan.FromMilliseconds(CloseTimeout);
                        await ChromiumProcess.EnsureExitAsync(closeTimeout).ConfigureAwait(false);
                    }

                    // Now we can safely await the browser close operation without risking keeping chromium
                    // process running for indeterminate period.
                    await browserCloseTask.ConfigureAwait(false);
                }
                finally
                {
                    Disconnect();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);

                if (ChromiumProcess != null)
                {
                    await ChromiumProcess.KillAsync().ConfigureAwait(false);
                }
            }

            // Ensure that remaining targets are always marked closed, so that asynchronous page close
            // operations on any associated pages don't get blocked.
            foreach (var target in TargetsMap.Values)
            {
                target.CloseTaskWrapper.TrySetResult(false);
            }

            Closed?.Invoke(this, new EventArgs());
        }
Beispiel #2
0
        private async Task CloseCoreAsync()
        {
            try
            {
                try
                {
                    // Initiate graceful browser close operation but don't await it just yet,
                    // because we want to ensure chromium process shutdown first.
                    var browserCloseTask = Connection.SendAsync("Browser.close", null);

                    if (_chromiumProcess != null)
                    {
                        // Notify chromium process that exit is expected, but should be enforced if it
                        // doesn't occur withing the close timeout.
                        var closeTimeout = TimeSpan.FromMilliseconds(CloseTimeout);
                        await _chromiumProcess.EnsureExitAsync(closeTimeout).ConfigureAwait(false);
                    }

                    // Now we can safely await the browser close operation without risking keeping chromium
                    // process running for indeterminate period.
                    await browserCloseTask.ConfigureAwait(false);
                }
                finally
                {
                    Disconnect();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);

                if (_chromiumProcess != null)
                {
                    await _chromiumProcess.KillAsync().ConfigureAwait(false);
                }
            }

            Closed?.Invoke(this, new EventArgs());
        }