0
votes

Does anyone know how to show the progress of archives extracting, when using chilkat? I already have a progress bar called "progressBar1" on my form. At the moment the whole program freezes when extraction is started. Maybe have another thread? I'm using this code:

Chilkat.Rar rar = new Chilkat.Rar();

bool success;

success = rar.Open("abc123.rar");
if (success != true) {
    MessageBox.Show(rar.LastErrorText);
    return;
}

success = rar.Unrar("c:/temp/unrarDest/");
if (success != true) {
    MessageBox.Show(rar.LastErrorText);
}
else {
    MessageBox.Show("Success.");
}

If anyone has any alternative ways to extract .rar files, it would be great to know.
Thanks.

2
Thanks Tom Cabanski and Chris Tybur. I've got it working now using the BackgroundWorker component, and by calling it by using "backgroundWorker1.RunWorkerAsync();". Still haven't figured out how to make the progress bar work though. - Joey Morani
I don't know much about chilkat, but if that library can somehow generate status events while the UnRar method is extracting from the archive, you can handle those events and call the ReportProgress method of the BackgroundWorker component. In your form you would then handle the BackgroundWorker ProgressChanged event, and in that handler you would increment your progress bar. See stackoverflow.com/questions/614111/running-class-as-new-thread for more info. - Chris Tybur

2 Answers

2
votes

You are exactly correct. You would want to do the extraction in a background thread. The background thread should fire events to update the progress bar. Make sure to use Form.Invoke in your event handler when you make the call to update the progress bar.

2
votes

As Tom said, doing the extraction in another thread is the way to go. One way to do that is to use the BackgroundWorker component. It will fire off a separate thread where you can do the extraction, and you can have it periodically raise events that are handled in the UI thread for updating a progress bar.