第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

調(diào)用線程無法訪問此對象,因為其他線程擁有該對象。

調(diào)用線程無法訪問此對象,因為其他線程擁有該對象。

慕仙森 2019-06-10 21:03:18
調(diào)用線程無法訪問此對象,因為其他線程擁有該對象。我的代碼如下public CountryStandards(){     InitializeComponent();     try     {         FillPageControls();     }     catch (Exception ex)     {         MessageBox.Show(ex.Message, "Country Standards", MessageBoxButton.OK, MessageBoxImage.Error);     }}/// <summary>/// Fills the page controls./// </summary>private void FillPageControls(){     popUpProgressBar.IsOpen = true;     lblProgress.Content = "Loading. Please wait...";     progress.IsIndeterminate = true;     worker = new BackgroundWorker();     worker.DoWork += new System.ComponentModel.DoWorkEventHandler(worker_DoWork);     worker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(worker_ProgressChanged);     worker.WorkerReportsProgress = true;     worker.WorkerSupportsCancellation = true;     worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);     worker.RunWorkerAsync();                    }private void worker_DoWork(object sender,      System.ComponentModel.DoWorkEventArgs e){     GetGridData(null, 0); // filling grid}private void worker_ProgressChanged(object sender,      System.ComponentModel.ProgressChangedEventArgs e){     progress.Value = e.ProgressPercentage;}private void worker_RunWorkerCompleted(object sender,      System.ComponentModel.RunWorkerCompletedEventArgs e){     worker = null;     popUpProgressBar.IsOpen = false;     //filling Region dropdown     Standards.UDMCountryStandards objUDMCountryStandards = new Standards.UDMCountryStandards();     objUDMCountryStandards.Operation = "SELECT_REGION";     DataSet dsRegionStandards = objStandardsBusinessLayer.GetCountryStandards(objUDMCountryStandards);     if (!StandardsDefault.IsNullOrEmptyDataTable(dsRegionStandards, 0))         StandardsDefault.FillComboBox(cmbRegion, dsRegionStandards.Tables[0], "Region", "RegionId");步驟objUDMCountryStandards.Country = txtSearchCountry.Text.Trim() != string.Empty ? txtSearchCountry.Text : null;在GET網(wǎng)格中,數(shù)據(jù)拋出異常。調(diào)用線程無法訪問此對象,因為其他線程擁有該對象。這里怎么了?
查看完整描述

3 回答

?
明月笑刀無情

TA貢獻(xiàn)1828條經(jīng)驗 獲得超4個贊

另一個很好的用途Dispatcher.Invoke用于在執(zhí)行其他任務(wù)的函數(shù)中立即更新UI:

// Force WPF to render UI changes immediately with this magic line of code...Dispatcher.Invoke(new Action(() => { }), 
.DispatcherPriority.ContextIdle);

我使用它將按鈕文本更新為“處理.。“同時禁用它WebClient請求。


查看完整回答
反對 回復(fù) 2019-06-10
?
慕姐8265434

TA貢獻(xiàn)1813條經(jīng)驗 獲得超2個贊

要添加我的2美分,即使您通過以下方式調(diào)用代碼,也可能出現(xiàn)異常System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke()
關(guān)鍵是你得打電話給Invoke().的.Dispatcher.的.控制您試圖訪問的,在某些情況下可能與System.Windows.Threading.Dispatcher.CurrentDispatcher..所以你應(yīng)該用YourControl.Dispatcher.Invoke()為了安全起見。在我意識到這一點之前我敲了幾個小時的頭。

更新

對于未來的讀者來說,這似乎在較新版本的.NET(4.0及以上版本)中發(fā)生了變化?,F(xiàn)在,在更新VM中的UI備份屬性時,您不必再擔(dān)心正確的調(diào)度器。WPF引擎將在正確的UI線程上封送跨線程調(diào)用。見更多細(xì)節(jié)這里..感謝@aaronburro的信息和鏈接。你也可以在下面的評論中閱讀我們的對話。


查看完整回答
反對 回復(fù) 2019-06-10
  • 3 回答
  • 0 關(guān)注
  • 1499 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號