//例一
delegate void AppendStringCallback(string text);
private void AppendString(string txt)
{
this.listView1.Items.Add(txt);
}
private void ReceiveDate()
{
AppendStringCallback appendStringCallback = new AppendStringCallback(AppendString);
this.Invoke(appendStringCallback, new object[] { string.Format("{0},{1},{2}", str1, str2 + "号", iepAddress.ToString()) });
}
//例二
namespace ThreadPoolDemo
{
public partial class ThreadForm : Form
{
// 定义delegate以便Invoke时使用
private delegate void SetProgressBarValue(int value);
// 跟SetProgressBarValue委托相匹配的方法
private void SetProgressValue(int value)
{
progressBar.Value = value;
}
// 使用Invoke方法来设置进度条
private void RunWithInvoke()
{
int value = progressBar.Value;
while (value< progressBar.Maximum)
{
//如果是跨线程调用
if (InvokeRequired)
{
this.Invoke(new SetProgressBarValue(SetProgressValue), value++);
}
else
{
progressBar.Value = ++value;
}
}
}
public ThreadForm()
{
InitializeComponent();
}
private void btnInvoke_Click(object sender, EventArgs e)
{
progressBar.Value = 0;
Thread thread = new Thread(new ThreadStart(RunWithInvoke));
thread.Start();
}
}
}
https://www.2cto.com/kf/201211/171457.html?uqzujo=inlaa2
!!https://www.cnblogs.com/songxingzhu/p/3677307.html
https://blog.youkuaiyun.com/thanks_hck/article/details/97273977
未完待续...