在我的项目中,我有一个busyindicator
并且我正在使用ListObject
inFirstMethod
和SecondMethod
.
该程序给出以下错误:
调用线程无法访问该对象,因为不同的线程拥有它
我正在使用以下代码:
public static readonly DependencyProperty ListObjectProperty =
DependencyProperty.Register("ListObject", typeof(ObservableCollection<FileViewModel>), typeof(MyObjectViewModel), new PropertyMetadata(ChangeCallback));
public ObservableCollection<FileViewModel> ListObject
{
get { return (ObservableCollection<FileViewModel>)GetValue(ListObjectProperty); }
set { SetValue(ListObjectProperty, value); }
}
private void SelectedPath()
{
NavigatePage(new Page2());
FirstMethod();
}
private void FilesCase()
{
var t = new Task(() => this.ThreadFilesCase());
t.ContinueWith(
(o) =>
{
Dispatcher.BeginInvoke(new Action(() =>
{
IsBusy = false; NavigatePage(new Page3());
}));
});
IsBusy = true;
t.Start();
}
private void ThreadFilesCase()
{
SecondMethod();
}