In my project I have a busyindicator
and I'm using ListObject
in FirstMethod
and SecondMethod
.
The program gives the following error:
The calling thread cannot access the object because a different thread owns it
I am using the following code:
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();
}