110,539
社区成员
发帖
与我相关
我的任务
分享
Thread oThread = new Thread(dofunction);
oThread.Start();
pivate void dofunction()
{
//run some function or code
//here end..
SendMessage(this.Handle, WM_CLOSE, (IntPtr)0, (IntPtr)0);
//这里,这样发消息给主线程或主窗体吧
会提示说 this.Handle 是一个错误的值,在调试中会中断,直接编译,然后运行不会报错
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.
}
pivate void dofunction()
{
//run some code....
//here end.....
setinfo_notidelegate sn=new setinfo_notidelegate()
//sn();
this.Invoke(sn);//inbokr 的参数得是委托函数 this.Invoke(函数,参数)
}
delegate void setinfo_notidelegate();
public void setinfo_noti_()
{
SendMessage(this.Handle, WM_CLOSE, (IntPtr)0, (IntPtr)0);
}
Thread oThread = new Thread(dofunction);
oThread.Start();
pivate void dofunction()
{
//run some code....
//here end.....
setinfo_notidelegate sn=new setinfo_notidelegate()
sn();
}