我試圖在用戶界面的變化,然後讓我的函數運行 這裏是我的代碼: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