I'm currently making improvements to my application and I'm moving the heavy piece of the application that does a lot of manual work to a different thread via Task.Run
var myTask = Task.Run(() => test()).ContinueWith((Finish) =>
{...}
test()
is the testing method that will be renamed of course, once this is working.
inside the test()
function I access Properties.Settings.Default.A
and that works just fine and few lines below I have an if statement where Properties.Settings.Default.B
is compared and I end up with:
"The calling thread cannot access this object because a different thread owns it."
I even tried making that an input parameter and then the input variable also gives the same error.
void test()
{
timer.Start();
SRCH_Status.Dispatcher.BeginInvoke((Action)(() => SRCH_Status.Content = "Retrieving information . . ."));
SRCH_Progress.Dispatcher.BeginInvoke((Action)(() => SRCH_Progress.Content = "Scanning in progress"));
if (Properties.Settings.Default.A == 0)
....
if (Properties.Settings.Default.B> 1) //ERROR HERE
{...}
...}
What am I doing wrong here?!
Here is the stackTrace property of the exception:
at System.Windows.Threading.Dispatcher.VerifyAccess()
at System.Windows.DependencyObject.ClearValue(DependencyPropertyKey key)
at System.Windows.Controls.ItemCollection.Clear()
at APP.Main.test() in c:\....\Main.xaml.cs:line 718
at APP.Main.<MENU_Start_Click>b__3() in c:\...\Main.xaml.cs:line 187
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()