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 7521675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:17:44+00:00 2026-05-30T02:17:44+00:00

I am working on this example, but I am unable to mesh the callback

  • 0

I am working on this example, but I am unable to mesh the callback and the threading.
What I want is this.
1) Press button
2) Start the progress bar running
3) Call to a new thread to perform some long running process
4) A callback on the long running process should trigger the progress bar to stop.

Below I have something…Although the callback parameter for DoSomethingInThread comes in as null.
The StopProgressBar() acts on the ProgressBar control, so it cannot be static.

    static bool done;
    static readonly object locker = new object();
    static ParameterizedThreadStart threadStarter = new ParameterizedThreadStart(DoSomethingInThread);  
    private Thread workerThread = new Thread(threadStarter);
    public delegate void StopProgressBarCallback()

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        StartProgressBar();
        workerThread.Start();
    }

    static void DoSomethingInThread(object callback)
    {
        StopProgressBarCallback stopper = callback as StopProgressBarCallback;
        lock (locker)
        {
            Thread.Sleep(5 * 1000);
        }
        stopper();
    }

    private void StartProgressBar()
    {
        progressBar1.MarqueeAnimationSpeed = 30;
        progressBar1.Style = ProgressBarStyle.Marquee;
    }

    public void StopProgressBar()
    {
        progressBar1.Style = ProgressBarStyle.Continuous;
    }
  • 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-05-30T02:17:45+00:00Added an answer on May 30, 2026 at 2:17 am

    Have a look at the backgroundworker class, it is more suitable for what you are trying to do and a whole lot easier to get to grips with!

    Generally, you shouldn’t ever be ‘newing’ up Thread instances. It is better to use the thread pool, a background worker or if you’re on .net 4, a task object from the thread parallel library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a bigger project atm, but I made this simple example to
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I have this simple example I can't seems to get working : MERGE INTO
What's the secret to getting ClaimsResponse working with DotNetOpenId ? For example, in this
I have this working definition: IDENTIFIER [a-zA-Z][a-zA-Z0-9]* I don't want to keep repeating the
I have this working great, but I'd like a deeper understanding of what is
Okay so im working on this php image upload system but for some reason
I had django-piston working a week ago but recently I'm unable to call any
Consider this example Javascript code: a = new Array(); a['a1']='foo'; a['a2']='bar'; b = new
I'm running Drupal 7.4 on localhost, and I've downloaded some themes/modules but I'm unable

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.