public virtual void Output(object sender, string outData) { object sendie = (sender as IIdeComponent)?.ParentIDE.Machine ?? sender; if (this.InvokeRequired) { if (!DataClients.ContainsKey(sendie)) { DataClients.Add(sendie, DataClients.Count); if (DataClientsColors.Count > DataClients.Count - 1) { DataClientsColors.RemoveAt(DataClients.Count - 1); } DataClientsColors.Insert(DataClients.Count - 1, XGraphics.HSV(55 * (int)DataClients.Count - 1, 80, 100)); } syncContext.Post(new SendOrPostCallback((o) => { if (!this.IsDisposed) { if (!_IsInputing) { if (ParentConsoleDevice.ColorDataClients) { rtbDisplay.SelectionColor = DataClientsColors[(int)DataClients[sendie]]; } _Output(sender, outData); if (ParentConsoleDevice.ColorDataClients) { rtbDisplay.SelectionColor = System.Drawing.Color.White; } } else { if (ParentConsoleDevice.ColorDataClients) { rtbDisplay.SelectionColor = DataClientsColors[(int)DataClients[sendie]]; } rtbDisplay.AppendText(outData); if (ParentConsoleDevice.ColorDataClients) { rtbDisplay.SelectionColor = System.Drawing.Color.White; } _PreText = rtbDisplay.Text; _PreRtf = rtbDisplay.Rtf; } } }), null); // giving console initializer thread time to update UI Thread.Sleep(10); } else { rtbDisplay.SelectionColor = System.Drawing.Color.White; _Output(sender, outData); } }
// // // #region Thread-safe wrapping public virtual void Input(object sender, out string inData, int length) { object sendie = (sender as IIdeComponent)?.ParentIDE.Machine ?? sender; if (this.InvokeRequired) { if (!DataClients.ContainsKey(sendie)) { DataClients.Add(sendie, DataClients.Count); if (DataClientsColors.Count > DataClients.Count - 1) { DataClientsColors.RemoveAt(DataClients.Count - 1); } DataClientsColors.Insert(DataClients.Count - 1, XGraphics.HSV(55 * (int)DataClients.Count - 1, 80, 100)); } object objInData = ""; if (!DataClients.ContainsKey(sendie)) { DataClients.Add(sendie, DataClients.Count); } this.Invoke(new Action <System.Drawing.Color>((c) => { rtbDisplay.SelectionColor = c; }) , DataClientsColors[(int)DataClients[sendie]]); var d = new Func <object, int, string>(_Input); objInData = this.Invoke(d, sender, length); inData = (string)objInData; if (!this.IsDisposed) { this.Invoke(new Action <System.Drawing.Color>((c) => { rtbDisplay.SelectionColor = c; }), Color.White); } } else { rtbDisplay.SelectionColor = System.Drawing.Color.White; inData = _Input(sender, length); } }