我的
--------------------------------
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.youkuaiyun.com/yangdayededaye/article/details/49147933