Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.