I want to make a program that zip by backup files, but the program hangs when zipping files. I tried to use backgroundworker to execute the work.
this is my code so far:
private: System::Void threadTest_Click(System::Object^ sender, System::EventArgs^ e) {
debug->Text = L"Zipping...";
zip->RunWorkerAsync();
if(zip->IsBusy)
{
bkProgress->Increment(20);
Application::DoEvents();
}
//zip->OnDoWork();
}
This is DoWork code for my backgroundworker:
private: System::Void zip_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
//zipping file code here
refreshAll();
}
I found out that refreshAll()won’t run and I can’t tell when the thread is stopped, I think I did something wrong here, can you give me some tips, I am really new to CLR. Thanks
if RefreshAll make changes to GUI, you have to take care to the following rule:
Never change the GUI from another thread than the main thread where the Gui was created.
In you case you have to use Form::Invoke method to switch to the main thread like that
And of course you have to create a delegate RefreshAllDelegate.