调用线程无法访问此对象,因为其他线程拥有该对象。我的代码如下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网格中,数据抛出异常。调用线程无法访问此对象,因为其他线程拥有该对象。这里怎么了?
3 回答
明月笑刀无情
TA贡献1828条经验 获得超4个赞
Dispatcher.Invoke
// Force WPF to render UI changes immediately with this magic line of code...Dispatcher.Invoke(new Action(() => { }), .DispatcherPriority.ContextIdle);
WebClient
慕姐8265434
TA贡献1813条经验 获得超2个赞
System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke()
. Invoke()
Dispatcher
System.Windows.Threading.Dispatcher.CurrentDispatcher
YourControl.Dispatcher.Invoke()
更新
- 3 回答
- 0 关注
- 1443 浏览
添加回答
举报
0/150
提交
取消