Problems with BackGroundWorker

  • Thread starter Thread starter CH
  • Start date Start date
C

CH

Hy,
I have a backgroundworker doing some work when the user presses a
button, the problem is when I quickly start and stop the
backgroundworker, after 3-4 starts the DoWork event doesn't fire
anymore.
What usualy happends is this:
1. start the worker
2. immediately stop the worker (everything is OK)

3. immediately start the worker
4. immediately stop the worker (everything is OK)

5 immediately start the worker (the event handler for DoWork is not
called)

Anyone got any ideas on what happens?

Thanks
 
I think the threads blocks somewhere after
workerthread.RunWorkerAsync() and before the DoWork event handler.
Is this possible
 
Hy,
I have a backgroundworker doing some work when the user presses a
button, the problem is when I quickly start and stop the
backgroundworker, after 3-4 starts the DoWork event doesn't fire
anymore.
What usualy happends is this:
1. start the worker
2. immediately stop the worker (everything is OK)

3. immediately start the worker
4. immediately stop the worker (everything is OK)

5 immediately start the worker (the event handler for DoWork is not
called)

Anyone got any ideas on what happens?

Thanks

How are you canceling? Without any of your code, it will be hard to
tell..
 
Thank you for the reply here are pieces of my code (he relevant ones:)

//
//runGraphs
//
this.mrunGraphs = new BackgroundWorker();
this.mrunGraphs.WorkerReportsProgress = true;
this.mrunGraphs.WorkerSupportsCancellation = true;
this.mrunGraphs.DoWork += new
DoWorkEventHandler(runGraphs_DoWork);
this.mrunGraphs.ProgressChanged += new
ProgressChangedEventHandler(runGraphs_ProgressChanged);
this.mrunGraphs.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(runGraphs_RunWorkerCompleted);


void buttonAnalyze_Click(object sender, EventArgs e)
{
this.theLog.WriteMessage("Analisys started");

this.DisableMainPanel();

if (mrunGraphs.IsBusy) theLog.WriteError("We are busy");

this.mrunGraphs.RunWorkerAsync();//send DoWork event //
LINE A

}

void runGraphs_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = new ArrayList(); //LINE B
this.RunShit((ArrayList)e.Result,e);
}


void runGraphs_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
this.EnableMainPanel();

if (e.Error != null)
{
LogWriter.WriteError(e.Error.Message);
return;
}
}

void runGraphs_ProgressChanged(object sender, ProgressChangedEventArgs
e)
{
AdvancedStatus CurrentStatus =
(AdvancedStatus)e.UserState;

this.manalysingForm.UpdateBar(CurrentStatus.Progress);

this.manalysingForm.UpdateBarOverall(CurrentStatus.OverallProgress);
}


//button1 is on the status reporting form mfather is the main form
private void button1_Click(object sender, EventArgs e)
{
this.mfather.StopWorkerThread();
this.Hide();
}

public void StopWorkerThread()
{
this.mrunGraphs.CancelAsync();
}

Somewhere between LINE A and LINE B the thread blocks

Hope you can find the problems,
Thanks,
Dan Ionut Fechete
 
Back
Top