Umm I do not see any code for your worker.. it doesn't seem to have any work to do :S
Your program itself seems to be doing the work and then you call backgroundworker() which isn't shown here..
Backgroundworker is a thread.. where you give it work to do while the program does something else.. then the program gathers the work while the thread sleeps..
When the thread is done working, there is a command to tell the program it is finished and then it *joins* and sleeps.
Calling RunWorkerAsync when the work is already being done will result in *InvalidOperationException*
This Code would definitely get around that problem.. But it only allows you to run whatever is in the backgroundWorker_DoWork Function..
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
backgroundWorker1->DoWork();
//Program does other stuff here while backgrounder worker does other stuff.
}
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
//Does calculations and all the work here.
Thread::Sleep(1000); //Thread must sleep or else u may find a huge increase in CPU usage.
}
For Running Worker Asynchronously, you definitely have to do something like this:
http://msdn.microsoft.com/en-us/library/waw3xexc.aspx
What happens is that they call runworkerasync() and it does the work specified.. then it reports when its completed or if its cancelled and then the thread sleeps or is given more work to do. RunWorkerAsync can be given more work where as DoWork() just does work that is already pre-defined.. thats the only differences.
…