日期:2014-05-20  浏览次数:20765 次

多线程调用UI线程下的方法
public   void   getcontent(string   content){
Monitor.Enter   (this);
m_spiderForm.SetContent(content);
Monitor.Pulse(this);
Monitor.Exit(this);
}

SetContent(string   str)是窗口m_spiderForm下的方法:
public   void   SetContent(string   content){
此处我可以获得getcontent传过来的content,但调用UI线程时老是无法执行savedata()方法保存.
//这里我要处理的就是调用savedata这个函数,利用多线程(注意:要求一定要利用多线程,因为要将content处理,需要一定的时间)将content保存到数据库,并绑定datagrid;在这里如何实现它呢?????请高手指点.谢谢
}
public   void   savedata(){
        ................
        datagrid.datasource   =   dt;
        ........
}

------解决方案--------------------
public delegate void SetContentDelegate(string str)
public void SetContent(string content)
{
if(this.invokerequired)
{
SetContentDelegate d=new SetContentDelegate(SetContent)
this.invoke(d, new object[]{content});
}
else
{
//正常代码
}
}


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

最新版本:20070212

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