Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:07:22+00:00 2026-06-12T02:07:22+00:00

i have a strange situation. please see the backgroundWorker5_RunWorkerCompleted event: private void backgroundWorker5_RunWorkerCompleted(object sender,

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:07:23+00:00Added an answer on June 12, 2026 at 2:07 am

    As requested;

    What do you mean by “a loop that never ends”? A Thread.Sleep on 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:

    What are you trying to achieve? As far as I can guess, you are doing
    some work in a background thread – backgroundWorker5 – (the UI thread
    is responsive). When backgroundWorker5 is finished you want to start a
    timer and display a counter in a label while the UI is still
    responsive (for somebody to stop the timer maybe?). Something like
    that? – Mario 3 mins ago edit

    yes you are right. i want a loop and it never stops until a user click
    cancel button. – MoonLight 1 min ago

    So, try something like this:

    int time = 0;
    
    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.Interval = 1000; //<--- Tick each second, you can change this.
            timer1.Enabled = true;
            timer1.Start();
            // MessageBox.Show("start timer");
        }
    }
    
    private void timer1_Tick(object sender, EventArgs e)
    {
        lblTimer.Text = (time + 1).ToString();
    }
    
    private void button_Cancel_Click(object sender, EventArgs e)
    {
        //MessageBox.Show("end timer");
        timer1.Enabled = false;
        timer1.Stop();
        lblTimer.Text = "0";
        btnStartAdventures.PerformClick();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a strange situation happening. I have a <h3> with text in it. When
I have a strange situation in regards to xml serialization... If I run MyApp.exe
I have a strange situation here. In my android app, I have a layout
I have a very strange situation. I have a large set of records to
I have a very strange situation. I´m working on a pretty big Java application
I have the next very strange situation and problem: .NET 4.0 application for diagram
Strange situation. If I have these tables: CREATE TABLE t1 (id INT, title VARCHAR(20),
I have a strange situation using asp ajax chart controls. I have an application
I have a strange situation where i have added a reference to Microsoft.SqlServer.Smo Microsoft.SqlServer.ConnectionInfo
I have a strange situation. I have a fairly memory intense process (image processing)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.