Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Background worker CancelAsync Issue

Status
Not open for further replies.

gasca

Programmer
Apr 2, 2003
22
ES
Hi I'm trying to adapt a code from as I started to write an application to read several mp3 headers from files and application was hanging up.

Before now, when I was pressing cancel button, application was simply doing nothing (no catching cancelAsync method), now it throws a run-time exception at that time.

This is the basic layout:

private readdirectories (DoWorkEventArgs e) {
BackgroundWorker bwg = sender as BackgroundWorker;

e.Result = leerCabecerasMP3(bwg);
if (bwg.CancellationPending) {
e.Cancel = true;
}
}

private string leerCabecerasMP3(BackgroundWorker bwg) {

while (!bwg.CancellationPending) {
readheader;
bwg.ReportProgress(progreso);
}
return "OK"
}

And the button handlers

private void button1_Click(object sender, EventArgs e) {
Boton_CancelarMP3.Enabled = true;
boton_buscarMP3.Enabled = false;
proceso.RunWorkerAsync();
}

void proceso_actualizaprogress(object sender, ProgressChangedEventArgs e) {
progressBar1.Value = e.ProgressPercentage;
progressBar1.Refresh();
}
void proceso_fin(object sender, RunWorkerCompletedEventArgs e)
do something;
}

private void Boton_CancelarMP3_Click(object sender, EventArgs e) {
proceso.CancelAsync();
}


For anyone interested below is the full code.
 
you need to provide the details of the exception.
type
message
stack trace

the best way to capture this is catch the exception the write the exception.ToString(); somewhere, then throw the exception again and let the app fail.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi Jason for your help..

I decided to trace the error and i got:

StackTrace:
en System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
en System.ComponentModel.RunWorkerCompletedEventArgs.get_Result()
en WindowsFormsApplication1.PerfectTag.proceso_fin(Object sender, RunWorkerCompletedEventArgs e) en E:\Perfect Tags\PerfectTag v0.1\PerfectTag v0.1\Form1.cs:línea 93
en System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
en System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
InnerException:

What means that i was trying to get e.result before sucessful exit so it may be that e.result is not defined... so problem solved. Thank you anyway...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top