I'm trying to create a progress bar that will work asynchronously to the main process. I'm created a new event and invoked it however everytime I then try to perform operations on the progress bar I recieve the following error:
"The calling thread cannot access this object because a different thread owns it"
The following code is an attempt to send an instance of the progress bar to the event as an object, it obviously failed but it gives you an idea of what the code looks like.
private event EventHandler importing;
void MdbDataImport_importing(object sender, EventArgs e)
{
ProgressBar pb = (ProgressBar)sender;
while (true)
{
if (pb.Value >= 200)
pb.Value = 0;
pb.Value += 10;
}
}
private void btnImport_Click(object sender, RoutedEventArgs e)
{
importing += new EventHandler(MdbDataImport_importing);
IAsyncResult aResult = null;
aResult = importing.BeginInvoke(pbDataImport, null, null, null);
importing.EndInvoke(aResult);
}
Does anyone have ideas of how to do this.
Thanks in advance SumGuy.