怎样将多线程的结果显示在界面上
展开全部
C#从另外一个线程操作windows窗体上的控件,必须要使用委托,通过委托调用UI线程去操控控件
//这个是窗体线程MainFrm
public delegate void Delegate_ChangeCallBack(string _value);
public Delegate_ChangeCallBack dlg_Change;
public static MainFrm mainFrm;
private void MainFrm_Load(object sender, EventArgs e)
{
mainFrm = this;
dlg_Change = new Delegate_ChangeCallBack (ChangeUI);
}
private void ChangeUI(string _value)
{
this.txt_Change.text = _value;
//do something...
}
//下面是你的新线程
private void NewThread()
{
string _Id = "change";
MainFrm.mainFrm.BeginInvoke(MainFrm.mainFrm.dlg_Change , new object[] { _Id });
}
//这个是窗体线程MainFrm
public delegate void Delegate_ChangeCallBack(string _value);
public Delegate_ChangeCallBack dlg_Change;
public static MainFrm mainFrm;
private void MainFrm_Load(object sender, EventArgs e)
{
mainFrm = this;
dlg_Change = new Delegate_ChangeCallBack (ChangeUI);
}
private void ChangeUI(string _value)
{
this.txt_Change.text = _value;
//do something...
}
//下面是你的新线程
private void NewThread()
{
string _Id = "change";
MainFrm.mainFrm.BeginInvoke(MainFrm.mainFrm.dlg_Change , new object[] { _Id });
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询