/// <summary> /// This method is responsible for displaying recieved data in textBox. /// (ThreadSafety!) /// </summary> /// <param name="msg"></param> public void addDataToDisplay(String msg) { if (this.textBox1.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(addDataToDisplay); try { this.Invoke(d, new object[] { msg }); } catch (Exception e) { Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message); } } else { try { textBox1.Text = msg; if (m_autoCheck) { m_parentForm.sendDataViaPort("temp!"); } } catch (Exception e) { Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message); } } }
public void SetText(string text) { if (this.console.InvokeRequired) { SetTextCallBack stcb = new SetTextCallBack(SetText); this.Invoke(stcb, new object[] { text }); } else { if (!string.IsNullOrEmpty(text)) { this.console.AppendText(text + "\r\n"); } bool lockScrollBar = this.checkBox1.Checked; if (!lockScrollBar) { console.SelectionStart = console.Text.Length; console.ScrollToCaret(); } else { console.SelectionStart = mCurrentIndex; console.ScrollToCaret(); } } }
public void SetText(string text) { if (text == "") { if (textBox1.InvokeRequired) { SetTextCallBack st = new SetTextCallBack(SetText); this.Invoke(st, new object[] { text }); } else { textBox1.Text = "\n"; } } else { if (textBox1.InvokeRequired) { SetTextCallBack st = new SetTextCallBack(SetText); this.Invoke(st, new object[] { text }); } else { textBox1.Text = text + "\n"; } } }
public static void AppendTextByAsync(this RichTextBox rtBox, string text, Color color, bool addNewLine = true) { try { if (rtBox.IsDisposed) { return; } if (rtBox.InvokeRequired) { SetTextCallBack stcb = new SetTextCallBack(AppendTextColorful); rtBox.Invoke(stcb, new object[] { rtBox, text, color, addNewLine }); } else { if (addNewLine) { text += Environment.NewLine; } rtBox.SelectionStart = rtBox.TextLength; rtBox.SelectionLength = 0; rtBox.SelectionColor = color; rtBox.AppendText(text); rtBox.SelectionColor = rtBox.ForeColor; rtBox.SelectionStart = rtBox.Text.Length; //Set the current caret position at the end rtBox.ScrollToCaret(); //Now scroll it automatically } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.StackTrace); } }
public FrmProgress() { InitializeComponent(); _setProgressText = SetProgressBarText; _setProgressValue = SetProgressBarValue; }
private void btnConnect_Click(object sender, EventArgs e) { try { //实例一个socket对象 client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = IPAddress.Parse(txtIp.Text); int port = Convert.ToInt32(txtPort.Text); IPEndPoint ie = new IPEndPoint(ip, port); client.Connect(ie); setCallBack = setValue; receiveCallBack = receiveData; this.rtxtRecv.Invoke(setCallBack, "已经成功连接到服务器!"); thReceive = new Thread(new ThreadStart(Receive)); thReceive.IsBackground = true; thReceive.Start(); } catch (Exception ex) { MessageBox.Show("连接服务器时出错:" + ex.ToString()); } }
/// <summary> /// This method is responsible for displaying recieved data in textBox. /// (ThreadSafety!) /// </summary> /// <param name="msg"></param> public void addDataToDisplay(String msg) { if (this.textBox1.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(addDataToDisplay); try { this.Invoke(d, new object[] { msg }); } catch (Exception e) { Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message); } } else { try { textBox1.AppendText(msg+"\n"); } catch (Exception e) { Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message); } } }
private void button_Connect_Click(object sender, EventArgs e) { try { socketSend = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = IPAddress.Parse(this.textBox_IP.Text.Trim()); socketSend.Connect(ip, Convert.ToInt32(this.textBox_Port.Text.Trim())); //实例化回调 setCallBack = new SetTextCallBack(SetValue); receiveCallBack = new ReceiveMsgCallBack(SetValue); this.richTextBox_Log.Invoke(setCallBack, "连接成功"); //开启一个新的线程不停的接收服务器发送消息的线程 threadReceive = new Thread(new ThreadStart(Receive)); //设置为后台线程 threadReceive.IsBackground = true; threadReceive.Start(); } catch (Exception ex) { MessageBox.Show("连接服务端出错:" + ex.ToString()); } }
/// <summary> /// 连接 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void connect_Click(object sender, EventArgs e) { try { // IPHostEntry hostInfo = Dns.GetHostEntry("47.100.46.2"); // IPAddress ipAddress = hostInfo.AddressList[0]; // txt_IP = "superpao.aiweber.com/socket"; // txt_Port = "80"; socketSend = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = IPAddress.Parse("47.100.46.2"); socketSend.Connect(ip, 2120); //实例化回调 setCallBack = new SetTextCallBack(SetValue); receiveCallBack = new ReceiveMsgCallBack(SetValue); // this.Label.Invoke(setCallBack, "连接成功"); this.label1.Text = "receive successful" + receiveCallBack.ToString(); // MessageBox.Show("lianjieco:" + setCallBack.ToString()); //开启一个新的线程不停的接收服务器发送消息的线程 threadReceive = new Thread(new ThreadStart(Receive)); //设置为后台线程 threadReceive.IsBackground = false; threadReceive.Start(); } catch (Exception ex) { MessageBox.Show("连接服务端出错:" + ex.ToString()); } }
private void setText(string text) { //try { if (this.textBox1.InvokeRequired) { while (!this.textBox1.IsHandleCreated) { if (this.textBox1.Disposing || this.textBox1.IsDisposed) { return; } } SetTextCallBack d = new SetTextCallBack(setText); this.textBox1.Invoke(d, new object[] { text }); } else { this.textBox1.Text = text; } } //catch (System.Exception ex) //{ // string str = ex.Message; //} }
/// <summary> /// Adds text to text box and to graph. /// </summary> /// <param name="msg"></param> public void addDataToDisplay(String msg) { if (this.textBox1.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(addDataToDisplay); try { this.Invoke(d, new object[] { msg }); } catch (Exception e) { Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message); } } else { try { textBox1.Text = msg; double x, y1; DateTime dt = DateTime.Now; x = new XDate(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); msg = msg.Trim(); //parsing to double bug fix int firstPart = 0; int lastPart = 0; if (msg.Length == 4) { firstPart = Int32.Parse(msg.Substring(0, 2)); lastPart = Int32.Parse(msg.Substring(3, 1)); } else if (msg.Length == 3) { firstPart = Int32.Parse(msg.Substring(0, 1)); lastPart = Int32.Parse(msg.Substring(2, 1)); } y1 = firstPart + (0.1 * lastPart); m_pairList.Add(x, y1); m_pane.AxisChange(); zedGraphControl1.AxisChange(); zedGraphControl1.Refresh(); if (m_check) { m_parentForm.sendDataViaPort("temp!"); } } catch (Exception e) { Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message); } } }
//EventLog myLog = new EventLog(); public FrmProgress() { InitializeComponent(); _setProgressText = SetProgressBarText; _setProgressValue = SetProgressBarValue; //myLog.Source = "ForLABLog"; }
public FrmProgress(MorbidityForecast forecast, InventoryAssumption invAssumption) { //this._morbidityForm = morbidityForm; this._forecast = forecast; this._invAssumption = invAssumption; InitializeComponent(); _setProgressText = new SetTextCallBack(SetProgressBarText); _setProgressValue = new SetProgressBarCallBack(SetProgressBarValue); }
private void SetText(string text) { if (textBox1.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(SetText); this.Invoke(d, new object[] { text }); } else { this.textBox1.Text = text; } }
// This method demonstrates a pattern for making thread-safe // calls on a Windows Forms control. // // If the calling thread is different from the thread that // created the TextBox control, this method creates a // SetTextCallback and calls itself asynchronously using the // Invoke method. // // If the calling thread is the same as the thread that created // the TextBox control, the Text property is set directly. private void SetText(String stuff) { if (this.pingLabel.InvokeRequired) { SetTextCallBack s = new SetTextCallBack(SetText); this.Invoke(s, new object[] { stuff }); } else { pingLabel.Text = stuff; } }
private void setrcvback(String txt) { if (this.btn_num.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(setrcvback); this.Invoke(d, new object[] { txt }); } else { btn_num.Text = txt; } }
public void ChangeButtonText(String txt) { if (outputBox.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(ChangeButtonText); this.Invoke(d, new object[] { txt }); } else { this.button1.Text = txt; } }
private void SetText(string text) { if (this.txtLogInfo.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(SetText); this.Invoke(d, new object[] { text }); } else { this.txtLogInfo.Text = text; } }
public void Populator(string txt) { if (this.InvokeRequired) { SetTextCallBack txtCall = new SetTextCallBack(Populator); this.Invoke(txtCall, txt); } else { cb_serv.Items.Add(txt); } }
public void SetTextchat(string txt) { if (this.InvokeRequired) { SetTextCallBack txtCall = new SetTextCallBack(SetTextchat); this.Invoke(txtCall, txt); } else { rc_chat.Text += txt + Environment.NewLine; } }
public void TitleSetup(string txt) { if (this.InvokeRequired) { SetTextCallBack txtCall = new SetTextCallBack(TitleSetup); this.Invoke(txtCall, txt); } else { this.Text = txt; } }
private void SetTip(string tip) { if (lbTip.InvokeRequired) { SetTextCallBack sb = new SetTextCallBack(SetTip); this.Invoke(sb, new object[] { tip }); } else { lbTip.Text = tip; } }
private void SetAccumTask(string count) { if (lbAccumTask.InvokeRequired) { SetTextCallBack sb = new SetTextCallBack(SetAccumTask); this.Invoke(sb, new object[] { count }); } else { lbAccumTask.Text = count; } }
public void SetText(string txt) { if (this.InvokeRequired) { SetTextCallBack txtCall = new SetTextCallBack(SetText); this.Invoke(txtCall, txt); } else { tb_logcommand.Text += " " + txt + Environment.NewLine; } }
private void SetlbHead(string head) { if (lbhead.InvokeRequired) { SetTextCallBack sb = new SetTextCallBack(SetlbHead); this.Invoke(sb, new object[] { head }); } else { lbhead.Text = head; } }
//handles requests coming for other threads, requiring invoke. public void displayIncomingText(string msg) { if (textIncoming.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(displayIncomingText); this.Invoke(d, new object[] { msg }); } else { this.textIncoming.AppendText(msg + newline); } }
private void SetText(string tekst) { if (textBox1.InvokeRequired) { SetTextCallBack f = new SetTextCallBack(SetText); this.Invoke(f, new object[] { tekst }); } else { this.textBox1.Text = tekst; } }
private void SetText(string text) { if (this.txt_Recevicecontext.InvokeRequired) { SetTextCallBack stcb = new SetTextCallBack(SetText); this.Invoke(stcb, new object[] { text }); } else { this.txt_Recevicecontext.Text = text; } }
private void SetText(string tekst) { if (listBox1.InvokeRequired) { SetTextCallBack f = new SetTextCallBack(SetText); this.Invoke(f, new object[] { tekst }); } else { this.listBox1.Items.Add(tekst); } }
private void SetLoaclText(string text) { if (WebNowTime.InvokeRequired) { SetTextCallBack stcb = SetLoaclText; Invoke(stcb, text); } else { LocalNowTime.Text = text; } }
private void SetText5(string text) { if (this.textBox5.InvokeRequired) { SetTextCallBack stcb = new SetTextCallBack(SetText5); this.Invoke(stcb, new object[] { text }); } else { this.textBox5.Text = text; } }
void SetResultText(string text) { if (this.labelResult.InvokeRequired) { SetTextCallBack call = new SetTextCallBack(SetResultText); // 来自MSDN文档,递归思想 this.Invoke(call, new object[] { text }); } else { this.labelResult.Text = text; } }
private void ShowLog(string text) { if (this.logRichTxt.InvokeRequired) { SetTextCallBack stcb = new SetTextCallBack(ShowLog); this.Invoke(stcb, new object[] { text }); } else { this.logRichTxt.Text = string.Format("{0}\r\n{1}", this.logRichTxt.Text, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + text); } }
private void SetText2(string text) { if (this.lbBarcode.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(SetText2); this.Invoke(d, new object[] { text }); } else { lbBarcode.Text = text; } }
private void SetText(string text) { if (this.lbGTInput.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(SetText); this.Invoke(d, new object[] { text }); } else { lbGTInput.Text = text; } }
private void SetTextHTML(string tekst) { if (webBrowser1.InvokeRequired) { SetTextCallBack f = new SetTextCallBack(SetTextHTML); this.Invoke(f, new object[] { tekst }); } else { this.webBrowser1.Document.Write(tekst); } }
private void SetReceivedText(string text) { if (this.ServerConsoleListBox.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(SetReceivedText); this.Invoke(d, new object[] { text }); } else { this.ServerConsoleListBox.Items.Add(text); } }
public void displayStatusText(string msg) { if (lblStatus.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(displayStatusText); this.Invoke(d, new object[] { msg }); } else { this.lblStatus.Text = msg; } }
//write to displaybox in thread public void SetText(string text) { if (dataDisplayBox.InvokeRequired) { SetTextCallBack st = new SetTextCallBack(SetText); this.Invoke(st, new object[] { text }); } else { dataDisplayBox.AppendText(text + "\n"); if (this.checkBox_AutoscrollDown.Checked) { this.dataDisplayBox.ScrollToCaret(); } } }
/// <summary> /// Function Name: checker /// Created By: Kyle Avery /// Created On: 4/4/2013 /// Updated On: n/a /// Relys On: a string to be passed in /// Purpose: checks the threads and passes a string safely between them /// </summary> /// <param name="text"> text is the string we are going to pass between threads</param> private void setErrorText(string text) { if(this.l_errorCode.InvokeRequired) { try { SetTextCallBack d = new SetTextCallBack(setErrorText); this.Invoke(d, new object[] { text }); } catch { } } else { this.l_errorCode.Text = text; } }
/// <summary> /// This method is responsible for displaying recieved data in textBox. /// (ThreadSafety!) /// </summary> /// <param name="msg"></param> public void addDataToDisplay(String msg) { if (this.textBox1.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(addDataToDisplay); try { this.Invoke(d, new object[] { msg }); } catch (Exception e) { Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message); } } else { try { char[] arr = msg.ToCharArray(); int indexer = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.Length; i++) { if (arr[i] != '!') { sb.Append(arr[i]); } else { switch (indexer) { case 0: { textBox1.Text = sb.ToString(); break; } case 1: { textBox2.Text = sb.ToString(); break; } case 2: { textBox3.Text = sb.ToString(); break; } case 3: { textBox4.Text = sb.ToString(); break; } case 4: { textBox5.Text = sb.ToString(); break; } case 5: { if(sb.ToString().Equals("0")) { radioButton1.Enabled = true; radioButton1.Select(); radioButton2.Enabled = false; } else { radioButton1.Enabled = false; radioButton2.Enabled = true; radioButton2.Select(); } break; } } sb = null; sb = new StringBuilder(); indexer++; } } } catch (Exception e) { Form1.logException("Exception while adding to Console.textBox1 msg = " + e.Message); } } }
public void displayStatusText(string msg) { if (outputBox.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(displayStatusText); this.Invoke(d, new object[] { msg }); } else { this.outputBox.Text += msg + "\n"; outputBox.SelectionStart = outputBox.Text.Length; outputBox.ScrollToCaret (); } }
public void displayOutgoingText(string msg) { if (codeBox.InvokeRequired) { SetTextCallBack d = new SetTextCallBack(displayOutgoingText); this.Invoke(d, new object[] { msg }); } else { this.codeBox.Text = msg; codeBox.SelectionStart = codeBox.Text.Length; codeBox.ScrollToCaret (); } }