reset winform counter after backgroundWorker1_RunWorkerCompleted - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

reset winform counter after backgroundWorker1_RunWorkerCompleted

eyal12345eyal12345 Posts: 2Member
Hi
i have a simple winform using [b]backgroundWorker1[/b]
inside the [b]backgroundWorker1_DoWork [/b]i am looping and counting something
and show the counter on the form using [b]InvokeRequired[/b]
The problem is when click Btn_arrang the first time everything works great
but when it finish the job and get to [b]backgroundWorker1_RunWorkerCompleted[/b]
and i press the button Btn_arrange_Click again the form starts at counter2 it ended tha lst time
[b]for exapmle[/b] if the counter2 was 10 the first time so the nexttime i press the arrange_click it will start from number ten even if i reset it to zero at backgroundWorker1_RunWorkerCompleted


[b]Here is my code with the counter[/b]
[code]
protected int Counter2=0;
private void Btn_arrange_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{

for (int i = 0; i < 3; ++i)
{
Add();
Counter2++;
}


}


public void Add()
{
if (Lblphotofound.InvokeRequired)
{
Lblphotofound.BeginInvoke(new MethodInvoker(delegate
{
Add();
}));
}
else
{

Lblphotofound.Text ="found" + Counter2 ";


}



}

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{

Counter2=0
}


[/code]
Sign In or Register to comment.