我的
--------------------------------
this.chartAttMed.Invoke(new EventHandler(delegate
{
chartAttMed.Series[0].Points.AddXY(currentSecond, temp);
}));
this. 部件 .Invoke(new EventHandler(delegate
{
部件内的修改,
}));
------------
轉載
invoke方法的初衷是為了解決在某個非某個控件建立的線程中重新整理該控件可能會引發異常的問題。說的可能比較拗口,舉個例子:主線程中存在一個文本控件,在一個子線程中要改變該文本的值,此時會有可能引發異常。
為了避免該問題,需要在子線程中使用invoke方法來封裝重新整理文本内容的函數。Invoke 或者 BeginInvoke 去調用,兩者的差別就是Invoke 會導緻工作線程等待,而BeginInvoke 則不會
using System.Threading;
public delegate void MyInvoke(string str);//invoke方法建立委托
private void btnStartThread_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(DoWord));
thread.Start();
}
public void DoWord()
{
MyInvoke mi = new MyInvoke(SetTxt);//執行個體化一個委托,并且指定委托方法
BeginInvoke(mi,new object[]{"abc"}); //調用invoke方法
}
public void SetTxt(string str)//委托對應的方法
{
txtReceive.Text += "invoke";
}
https://blog.csdn.net/yangdayededaye/article/details/49147933