Microsoft.R.Debugger.AD7Engine.ExitBrowserAsync C# (CSharp) Method

ExitBrowserAsync() private method

private ExitBrowserAsync ( IRSession session ) : System.Threading.Tasks.Task
session IRSession
return System.Threading.Tasks.Task
        private async Task ExitBrowserAsync(IRSession session) {
            await TaskUtilities.SwitchToBackgroundThread();

            var cts = new CancellationTokenSource(1000);
            IRSessionInteraction inter;
            try {
                inter = await session.BeginInteractionAsync(true, cts.Token);
            } catch (OperationCanceledException) {
                // If we couldn't get a prompt to put "Q" into within a reasonable timeframe, just
                // abort the current interaction;
                await session.CancelAllAsync();
                return;
            }

            using (inter) {
                // Check if this is still the same prompt as the last Browse prompt that we've seen.
                // If it isn't, then session has moved on already, and there's nothing for us to exit.
                RBrowseEventArgs currentBrowseDebugEventArgs;
                lock (_browseLock) {
                    currentBrowseDebugEventArgs = _currentBrowseEventArgs;
                }

                if (currentBrowseDebugEventArgs != null && currentBrowseDebugEventArgs.Context.Contexts == inter.Contexts) {
                    await inter.RespondAsync("Q\n");
                }
            }
        }