Hi folks,
I'm trying to put together my first usage of BackgroundWorker. The problem is that the compiler is throwing the following exception in Debug mode:
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
Once that happens, no code after ReportProgress runs (the Debug::WriteLine() func does not execute). The exception is being thrown anytime I try to call the Worker's Report-Progress method from within its Do-Work method. My Do-Work method is as follows:
void backgroundWorkerFolderAnalysis_DoWork( Object^ sender, DoWorkEventArgs^ e ){
BackgroundWorker^ bgWorker =
dynamic_cast<BackgroundWorker^>(sender);bgWorker->ReportProgress(0);
Debug::WriteLine("Point A");
}
My Progress-Changed method is empty:
void backgroundWorkerFolderAnalysis_ProgressChanged( Object^ sender, ProgressChangedEventArgs^ e ){
/ Debug::WriteLine(Convert::ToString(0));}
My setup for the BackgroundWorker is:
backgroundWorkerFolderAnalysis->RunWorkerCompleted +=
gcnew RunWorkerCompletedEventHandler( this, &Form1::backgroundWorkerFolderAnalysis_RunWorkerCompleted );backgroundWorkerFolderAnalysis->DoWork +=
gcnew DoWorkEventHandler(this, &Form1::backgroundWorkerFolderAnalysis_DoWork);backgroundWorkerFolderAnalysis->ProgressChanged +=
gcnew ProgressChangedEventHandler( this, &Form1::backgroundWorkerFolderAnalysis_ProgressChanged );backgroundWorkerFolderAnalysis->RunWorkerAsync();
Help !

BackgroundWorker InvalidOperationException
Emy_P
Ashish.Net
In your setup of BackgroundWorker do the following:
backgroundWorkerFolderAnalysis->WorkerReportsProgess = true;