Got a problem with updating a WPF control from an event.
I have a WPF single form GUI, and am creating a thread to do some work.
The thread messages back to the GUI two events, succeeded and failed events. In these events I want to notch a progress bar on one each time.
I cannot seem to access the progress bar as it tells me
"The calling thread cannot access this object because a different thread owns it."
Apparently this is because WPF objects inherit from Dispatch oojamaflip. Pages and pages of stuff to read and I'm up against a deadline.
Can someone post some code to update the progress bar from within the event handler, and I can read up tonight.
Thanks in advance.
I have a WPF single form GUI, and am creating a thread to do some work.
The thread messages back to the GUI two events, succeeded and failed events. In these events I want to notch a progress bar on one each time.
I cannot seem to access the progress bar as it tells me
"The calling thread cannot access this object because a different thread owns it."
Apparently this is because WPF objects inherit from Dispatch oojamaflip. Pages and pages of stuff to read and I'm up against a deadline.
Can someone post some code to update the progress bar from within the event handler, and I can read up tonight.
Thanks in advance.
void _emailTotalCountMessage(object sender, MailFolder.EmailTotalCountMessageEventArgs e)
{
try
{
//The line below which is commented out was failing
//pbTotalProgress.Maximum = Convert.ToDouble(e.mailCount);
//All this nonsense below should work according to what I read but doesn't.
pbTotalProgress.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal , new Action(
delegate()
{
pbTotalProgress.Maximum = Convert.ToDouble(e.mailCount);
}
));
}
catch(System.Exception ex)
{
Trace.WriteLine(ex.ToString());
}
}
{
try
{
//The line below which is commented out was failing
//pbTotalProgress.Maximum = Convert.ToDouble(e.mailCount);
//All this nonsense below should work according to what I read but doesn't.
pbTotalProgress.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal , new Action(
delegate()
{
pbTotalProgress.Maximum = Convert.ToDouble(e.mailCount);
}
));
}
catch(System.Exception ex)
{
Trace.WriteLine(ex.ToString());
}
}
Comment