Cross thread modify UI
myUI1(txtPLC1, listBox1, listBox2);
private delegate void myUICallBack1(Control txtPLC1, Control list1, Control list2);
private void myUI1(Control txtPLC1, Control list1, Control list2)
{
if (this.InvokeRequired)
{
//Fix code
myUICallBack1 myUpdate1 = new myUICallBack1(myUI1);
this.Invoke(myUpdate1, txtPLC1, list1, list2);
}
else
{
//UI
txtPLC1.Text = PlcStatus1.ToString();
listBox1.Items.Insert(0, "*****");
listBox2.Items.Insert(0, sReturnData);
}
}
from https://social.msdn.microsoft.com/Forums/zh-TW/47d4b39e-7af0-4875-a69b-e36e0a932b87/-textbox1-?forum=233
delegate void SetTextCallback(string s);
private void UpdateUI(string log)
{
textBoxLog.Text = DateTime.Now.ToString() + " " + log + System.Environment.NewLine + textBoxLog.Text;
if (textBoxLog.Text.Length > 10000)
{
textBoxLog.Text = textBoxLog.Text.Substring(0, 5000);
}
}
public void ThreadSaveNG_File()
{
SetTextCallback stc = new SetTextCallback(this.UpdateUI);
this.BeginInvoke(stc, "log some thing");
}
public void ThreadShowPrintID(String id)
{
SetTextCallback stc = delegate(String id2) { labelLastUpdateString.Text = id2; };
this.BeginInvoke(stc, id);
}
留言
張貼留言