blairacuda
Technical User
hello,
i am writing up my first backgroundworker and while it seems like a great tool i am running into a wall.
scenario: we have a vb6 project that we are slowly migrating to c#. all of our new tools/windows are planned to be written in c#. so i have a class that is com accessible that launches a wpf form. when the form loads i am kicking off the following code:
qLib.BuildItemList is the reason for wanting have the background worker. the list is built by reading a database and the amount of items can be huge. progressBar1 is an Indeterminate progress bar that bounces while the list is being built and is a member of the wpf form; don't care about truly reporting progress right now. i collapsing the progress bar in bgw_ProgressChanged because that is what i read you are supposed to update UI elements. i've tried it there and in bgw_RunWorkerCompleted and receive the same result. the result being:"The calling thread cannot access this object because a different thread owns it.".
in the solution containing my com accessible assembly i have a tester form with a button that calls the same code as my vb6 project. this tester project works fine with the code above but calling the same method from vb6 results in the error
CBlair
Crystal, InstallShield, branching out in other programming realms.
i am writing up my first backgroundworker and while it seems like a great tool i am running into a wall.
scenario: we have a vb6 project that we are slowly migrating to c#. all of our new tools/windows are planned to be written in c#. so i have a class that is com accessible that launches a wpf form. when the form loads i am kicking off the following code:
Code:
private void LoadUpItems()
{
bgw = new BackgroundWorker();
bgw.WorkerSupportsCancellation = false;
bgw.WorkerReportsProgress = true;
bgw.DoWork += new DoWorkEventHandler( bgw_DoWork );
bgw.ProgressChanged += new ProgressChangedEventHandler( bgw_ProgressChanged );
bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler( bgw_RunWorkerCompleted );
bgw.RunWorkerAsync();
}
private void bgw_DoWork( object sender, DoWorkEventArgs e )
{
qLib.BuildItemList( false );
bgw.ReportProgress( 100 );
}
private void bgw_ProgressChanged( object sender, ProgressChangedEventArgs e )
{
progressBar1.Visibility = System.Windows.Visibility.Collapsed;
}
private void bgw_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e )
{
qLib.CloseIfOpen();
}
qLib.BuildItemList is the reason for wanting have the background worker. the list is built by reading a database and the amount of items can be huge. progressBar1 is an Indeterminate progress bar that bounces while the list is being built and is a member of the wpf form; don't care about truly reporting progress right now. i collapsing the progress bar in bgw_ProgressChanged because that is what i read you are supposed to update UI elements. i've tried it there and in bgw_RunWorkerCompleted and receive the same result. the result being:"The calling thread cannot access this object because a different thread owns it.".
in the solution containing my com accessible assembly i have a tester form with a button that calls the same code as my vb6 project. this tester project works fine with the code above but calling the same method from vb6 results in the error
CBlair
Crystal, InstallShield, branching out in other programming realms.