Invoke和InvokeRequired在哪儿定义? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System.Threading; public delegate void MyInvoke(string str); 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"}); } public void SetTxt(string str) { txtReceive.Text += str + System.Environment.NewLine; } Control.Invoke 方法 (Delegate) :在拥有此控件的基础窗口句柄的线程上执行指定的委托。Control.InvokeRequired 属性获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中。delegate double CalculateMethod(double Diameter); static CalculateMethod cMethod;double result = 0; static void Main(string[] args){ cMethod = new CalculateMethod(Calculate);cMethod.BeginInvoke(5, new AsyncCallback(TaskFinished), null); } public static double Calculate(double Diameter){return Diameter * Math.PI;} public static void TaskFinished(IAsyncResult result){result=cMethod.EndInvoke(result);}参考 需求酒店制门卡软件扩展开发,实现自助刷门卡软件,看下可行不。 关于控制台程序路径的问题 ftp 怎么下载多个文件 关于重新绘制的问题 Delphi 归来 频繁版本升级的 .net 还有发展 么 ?(100分开帖讨论) 谁知道怎么按照空格分割字符? 关于iewebcontrol treeview的使用 c#+access开发问题 for 标准表达式中的数据类型不匹配 如何使用sqldmo实现sqlserver数据库异地备份 C# 该怎么读,分别用中文和英文。 如何取得某个Brush派生类中的Brush对象 C# 如何读取gps串口和gps数据?急......
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"});
} public void SetTxt(string str)
{
txtReceive.Text += str + System.Environment.NewLine;
}
Control.InvokeRequired 属性
获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,
因为调用方位于创建控件所在的线程以外的线程中。
delegate double CalculateMethod(double Diameter);
static CalculateMethod cMethod;
double result = 0;
static void Main(string[] args)
{
cMethod = new CalculateMethod(Calculate);
cMethod.BeginInvoke(5, new AsyncCallback(TaskFinished), null);
}
public static double Calculate(double Diameter)
{
return Diameter * Math.PI;
}
public static void TaskFinished(IAsyncResult result)
{
result=cMethod.EndInvoke(result);
}
参考