日期:2014-05-19  浏览次数:20790 次

帮我看看问题出在哪
//实例化
WebClass   web   =   new   WebClass();

//绑定事件  
web.SendMessage   +=   new   WebClass.SendMessageHandler(web_SendMessage);

                        Thread   th   =   new   Thread(web.Run);
                        th.Start();

//事件
                void   web_SendMessage(object   sender,   SendMessageArgs   e)
                {
                        listView1.Items[e.SiteName].SubItems[e.ColName].Text   =       e.Message;
                }

每当这个Sendmessage事件发生时   就会弹出错误  
Cross-thread   operation   not   valid:   Control   'listView1 '   accessed   from   a   thread   other   than   the   thread   it   was   created   on.   不能跨线程调用   ...
大家帮帮我   给我个解决方法呀   我的目的是想根据事件传过来的参数更新listview控件子项的文本。。。用的是vs2005



------解决方案--------------------
void web_SendMessage(object sender, SendMessageArgs e)
{
if(listView1.invokerequired)
{
SendMessageHandler d=new SendMessageHandler(web_SendMessage);
listView1.begininvoke(d,new object[]{sender, e});
}
else
{
listView1.Items[e.SiteName].SubItems[e.ColName].Text = e.Message;
}
}


*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

最新版本:20070212

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html