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");
}
}
}