我在我写的dll内有使用多线程连上server端
并有一个call back function告诉Form目前的联机状况Thread回传Form里的call back function
void OnStatus (int status, char* msg){
char buf[128];
sprintf(buf,"OnStatus::Code=%d,Msg=%s",status,msg);
AddMemo(buf);
}
Add Memo把讯息贴在一个ListBox里
void AddMemo(const char* msg) {
String ^Str= gcnew String(msg);
lbMemo->Items->Add(Str);
}目前碰到问题是在thread丢出OnStatus的事件后
Form会出现以下的exception
“Cross-thread operation not valid : Control ‘lbMemo’ accessed from a thread other than the thread it was created on
查了资料是要往InvokeRequired着手
不过不知该怎么写 还请各位大神帮忙
并有一个call back function告诉Form目前的联机状况Thread回传Form里的call back function
void OnStatus (int status, char* msg){
char buf[128];
sprintf(buf,"OnStatus::Code=%d,Msg=%s",status,msg);
AddMemo(buf);
}
Add Memo把讯息贴在一个ListBox里
void AddMemo(const char* msg) {
String ^Str= gcnew String(msg);
lbMemo->Items->Add(Str);
}目前碰到问题是在thread丢出OnStatus的事件后
Form会出现以下的exception
“Cross-thread operation not valid : Control ‘lbMemo’ accessed from a thread other than the thread it was created on
查了资料是要往InvokeRequired着手
不过不知该怎么写 还请各位大神帮忙
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货