Пример #1
0
 protected void frmConsole_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (e.CloseReason == CloseReason.UserClosing)
     {
         e.Cancel = true;
         if (_IsInputing)
         {
             if (MessageBox.Show($"Closing this window will dispose {ParentConsoleDevice.Title}"
                                 + $" and cancel input for {IsBusyInputtingBy}. Continue?", "Warning about IO device dispose"
                                 , MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
                 != DialogResult.OK)
             {
                 return;
             }
             _InputCancelled    = true;
             _DisposeAfterInput = true;
             _IsInputing        = false;
         }
         else
         {
             ParentConsoleDevice.Dispose();
         }
     }
 }
Пример #2
0
        protected string _Input(object sender, int length)
        {
            string inData;

            if (!this.IsDisposed)
            {
                IsBusyInputting    = true;
                IsBusyInputtingBy  = sender;
                InputtingForLength = length;

                _PreText                   = rtbDisplay.Text;
                _PreRtf                    = rtbDisplay.Rtf;
                rtbDisplay.ReadOnly        = false;
                rtbDisplay.TextChanged    += rtbDisplay_TextChanged;
                rtbDisplay.KeyDown        += rtbDisplay_KeyDown;
                rtbDisplay.SelectionStart  = rtbDisplay.TextLength;
                rtbDisplay.SelectionLength = 0;
                PostMessage(rtbDisplay.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);

                _IsInputing        = true;
                _InputCancelled    = false;
                _DisposeAfterInput = false;
                IVirtualMachine senderMachine = (sender as IInputPort)?.ParentIDE.Machine ?? sender as IVirtualMachine;
                while (_IsInputing && !_InputCancelled &&
                       !(senderMachine?.Status == VirtualMachineRunningStatus.Breaking ||
                         senderMachine?.Status == VirtualMachineRunningStatus.StandBy ||
                         senderMachine?.Status == VirtualMachineRunningStatus.Paused) &&
                       !(senderMachine?.RunningTask.Status == TaskStatus.Canceled ||
                         senderMachine?.RunningTask.Status == TaskStatus.RanToCompletion ||
                         senderMachine?.RunningTask.Status == TaskStatus.Faulted))
                {
                    Application.DoEvents();
                    Thread.Yield();
                }
                _IsInputing = false;
                if (!_InputCancelled && !(senderMachine?.Status == VirtualMachineRunningStatus.Breaking))
                {
                    inData = rtbDisplay.Text.Substring(_PreText.Length);
                }
                else
                {
                    Display.Rtf = _PreRtf;
                    inData      = null;
                }

                rtbDisplay.ReadOnly     = true;
                rtbDisplay.TextChanged -= rtbDisplay_TextChanged;
                rtbDisplay.KeyDown     -= rtbDisplay_KeyDown;
                if (ParentConsoleDevice.AutoScrollDisplayToEnd)
                {
                    PostMessage(rtbDisplay.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
                }

                IsBusyInputting    = false;
                IsBusyInputtingBy  = null;
                InputtingForLength = -1;

                if (_DisposeAfterInput)
                {
                    ParentConsoleDevice.Dispose();
                }
            }
            else
            {
                inData = null;
            }

            _CheckDisplayParameters();
            return(inData);
        }