i have a strange situation.
please see the backgroundWorker5_RunWorkerCompleted event:
private void backgroundWorker5_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
btnStartAdventures.Text = "Start Adventure";
btnStartAdventures.Enabled = true;
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
return;
}
if (e.Cancelled)
{
lblStatusValueInAdventures.Text = "Cancelled...";
}
else
{
lblStatusValueInAdventures.Text = "Completed";
timer1.Enabled = true;
timer1.Start();
// MessageBox.Show("start timer");
Thread.Sleep((int.Parse(txtDelayInAdventures.Text)) * 60000);
//MessageBox.Show("end timer");
timer1.Enabled = false;
timer1.Stop();
lblTimer.Text = "0";
btnStartAdventures.PerformClick();
}
}
and that Timer is :
private void timer1_Tick(object sender, EventArgs e)
{
this.Invoke(new MethodInvoker(delegate { lblTimer.Text = (int.Parse(lblTimer.Text) + 1).ToString(); }));
}
but this timer can not change lblTimer's Text.
how can i fix this problem?
EDIT:
that Thread.Sleep is necessary and i can not remove it.
i want a loop that never ends and those codes are for that.
thanks in advance
As requested;
What do you mean by “a loop that never ends”? A
Thread.Sleepon the UI thread (RunWorkerCompleted event executes on the UI thread) will effectively freeze the UI thread, which means that no interaction with the UI thread will be shown.Comments:
So, try something like this: