我试图在用户界面的变化,然后让我的函数运行 这里是我的代码:C#WPF调度员 - 不能得到它的权利
private void btnAddChange_Document(object sender, RoutedEventArgs e)
{
System.Threading.ThreadStart start = delegate()
{
// ...
// This will throw an exception
// (it's on the wrong thread)
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(changest));
//this.BusyIndicator_CompSelect.IsBusy = true;
//this.MainWindow_parent.BusyIndicator_MainWindow.IsBusy = true;
};
// Create the thread and kick it started!
new System.Threading.Thread(start).Start();
}
public void changest()
{
this.BusyIndicator_CompSelect.IsBusy = true;
this.MainWindow_parent.BusyIndicator_MainWindow.IsBusy = true;
t = "Creating document 1/2..";
}
我想在UI后运行功能更新/ ThreadStart“开始”结束后:
string x = "";
for(int i =0;i<=1000;i++)
{
x+= i.ToString();
}
MessageBox.Show(x);
那么我该怎么办? 先进的感谢, 丁。
这里是我试过(似乎没有工作= /):bgWorker.DoWork + =(s,ev)=> {bgWorker.ReportProgress();报告当前进度 this.BusyIndicator_CompSelect.IsBusy = true; this.MainWindow_parent.BusyIndicator_MainWindow.IsBusy = true; t =“正在创建文档1/2 ..”; bgWorker.ReportProgress(100); }; bgWorker.RunWorkerCompleted + =(s,ev)=> this.MainWindow_parent.MyAddDocumentFunc(lbOS.SelectedValue.ToString(),lbVersion.SelectedValue.ToString()); }; bgWorker.RunWorkerAsync(); – dinbrca 2011-03-03 20:47:42
@dinbrca:会发生什么?你有哪些异常/错误行为? – HCL 2011-03-03 21:02:37
没有发生异常,虽然它看起来像IsBusy值不会改变=/ – dinbrca 2011-03-03 22:16:01