Question

There is a button like below :

   private void btnStartAdventure_Click(object sender, EventArgs e)
    {
        if (backgroundWorker5.IsBusy)
        {
            btnStartAdventures.Enabled = false;
            lblStatusValueInAdventures.Text = "Canceling...";
            backgroundWorker5.CancelAsync();
        }
        else
        {
            txtLogInAdventures.Text = string.Empty;
            btnStartAdventures.Text = "Cancel";
            lblUsersDoneCountValueInAdventures.Text = "---";
            lblStatusValueInAdventures.Text = "Running...";


            backgroundWorker5.RunWorkerAsync();
        }
    }

i want to call btnStartAdventure_Click event again after backgroundWorker_RunWorkerCompleted job!
so there will be a loop that never ends.
i put:

Thread.Sleep(3600000);

at the end of backgroundWorker_RunWorkerCompleted().
now what code should i use for call btnStartAdventure_Click again?
is Timer good for my purpose or not?
how can i prevent hanging and crashes by doing that job?

thanks in advance

Was it helpful?

Solution

To fire the btnStartAdventure_Click event handler programmatically, you can call

// Call the Click event of btnStartAdventure.
btnStartAdventure.PerformClick();

Just put that code in the end of the backgroundWorker_RunWorkerCompleted event.

See this article for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top