async void powerShellContext_RunspaceChangedAsync(object sender, RunspaceChangedEventArgs e)
 {
     if (_waitingForAttach &&
         e.ChangeAction == RunspaceChangeAction.Enter &&
         e.NewRunspace.Context == RunspaceContext.DebuggedRunspace)
     {
         // Send the InitializedEvent so that the debugger will continue
         // sending configuration requests
         _waitingForAttach = false;
         await _messageSender.SendEventAsync(InitializedEvent.Type, null);
     }
     else if (
         e.ChangeAction == RunspaceChangeAction.Exit &&
         (_editorSession == null ||
          _editorSession.PowerShellContext.IsDebuggerStopped))
     {
         // Exited the session while the debugger is stopped,
         // send a ContinuedEvent so that the client changes the
         // UI to appear to be running again
         await _messageSender.SendEventAsync <ContinuedEvent, Object>(
             ContinuedEvent.Type,
             new ContinuedEvent
         {
             ThreadId            = 1,
             AllThreadsContinued = true
         });
     }
 }
        private async void HandleRunspaceChangedAsync(object sender, RunspaceChangedEventArgs e)
        {
            if (e.ChangeAction == RunspaceChangeAction.Enter)
            {
                this.RegisterPSEditFunction(e.NewRunspace);
            }
            else
            {
                // Close any remote files that were opened
                if (e.PreviousRunspace.Location == RunspaceLocation.Remote &&
                    (e.ChangeAction == RunspaceChangeAction.Shutdown ||
                     !string.Equals(
                         e.NewRunspace.SessionDetails.ComputerName,
                         e.PreviousRunspace.SessionDetails.ComputerName,
                         StringComparison.CurrentCultureIgnoreCase)))
                {
                    RemotePathMappings remotePathMappings;
                    if (this.filesPerComputer.TryGetValue(e.PreviousRunspace.SessionDetails.ComputerName, out remotePathMappings))
                    {
                        foreach (string remotePath in remotePathMappings.OpenedPaths)
                        {
                            await(this.editorOperations?.CloseFileAsync(remotePath)).ConfigureAwait(false);
                        }
                    }
                }

                if (e.PreviousRunspace != null)
                {
                    this.RemovePSEditFunction(e.PreviousRunspace);
                }
            }
        }
 private void PowerShellContext_RunspaceChanged(object sender, RunspaceChangedEventArgs e)
 {
     if (_debugStateService.WaitingForAttach &&
         e.ChangeAction == RunspaceChangeAction.Enter &&
         e.NewRunspace.Context == RunspaceContext.DebuggedRunspace)
     {
         // Sends the InitializedEvent so that the debugger will continue
         // sending configuration requests
         _debugStateService.WaitingForAttach = false;
         _debugStateService.ServerStarted.SetResult(true);
     }
     else if (
         e.ChangeAction == RunspaceChangeAction.Exit &&
         _powerShellContextService.IsDebuggerStopped)
     {
         // Exited the session while the debugger is stopped,
         // send a ContinuedEvent so that the client changes the
         // UI to appear to be running again
         _debugAdapterServer.SendNotification(EventNames.Continued,
                                              new ContinuedEvent
         {
             ThreadId            = 1,
             AllThreadsContinued = true
         });
     }
 }
        private void OnRunspaceChanged(object sender, RunspaceChangedEventArgs e)
        {
            switch (e.ChangeAction)
            {
            case RunspaceChangeAction.Enter:
                if (_debugStateService.WaitingForAttach &&
                    e.NewRunspace.RunspaceOrigin == RunspaceOrigin.DebuggedRunspace)
                {
                    // Sends the InitializedEvent so that the debugger will continue
                    // sending configuration requests
                    _debugStateService.WaitingForAttach = false;
                    _debugStateService.ServerStarted.SetResult(true);
                }
                return;

            case RunspaceChangeAction.Exit:
                if (_debugContext.IsStopped)
                {
                    // Exited the session while the debugger is stopped,
                    // send a ContinuedEvent so that the client changes the
                    // UI to appear to be running again
                    _debugAdapterServer.SendNotification(
                        EventNames.Continued,
                        new ContinuedEvent
                    {
                        ThreadId            = ThreadsHandler.PipelineThread.Id,
                        AllThreadsContinued = true,
                    });
                }
                return;
            }
        }