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

  • Home
  • SEARCH
  • 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 8487029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:07:05+00:00 2026-06-10T21:07:05+00:00

Currently I have a background thread whose doWork calls a function similar to below.

  • 0

Currently I have a background thread whose doWork calls a function similar to below.

private void ThreadForAnalyzingReqFile_DoWork(object sender, DoWorkEventArgs e) 
{
    AnotherClass.AVeryLongTimedFunction();
}

Now, the code shall wait until AVeryLongTimedFunction() in AnotherClass finishes (that may take about 1-2 minutes) While this happens, how do I know exactly what’s happening? Is there any way I can be notified that function (in another class) finishes?

This thread is in my MainWindow class of WPF. I am using Visual Studio 2010.

  • 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-10T21:07:07+00:00Added an answer on June 10, 2026 at 9:07 pm

    There are many ways to do this. Two easy options:

    (1) Create an event in your UI class such as UpdateProgress, and notify that event at meaningful intervals

    Example:

        private void ThreadForAnalyzingReqFile_DoWork(object sender, DoWorkEventArgs e)
        {
            AnotherClass processor = new AnotherClass();
            processor.ProgressUpdate += new AnotherClass.ReallyLongProcessProgressHandler(this.Processor_ProgressUpdate);
            processor.AVeryLongTimedFunction();
        }
    
        private void Processor_ProgressUpdate(double percentComplete)
        {
    
            this.progressBar1.Invoke(new Action(delegate()
            {
                this.progressBar1.Value = (int)(100d*percentComplete); // Do all the ui thread updates here
            }));
        }
    

    And in “AnotherClass”

    public partial class AnotherClass
    {
        public delegate void ReallyLongProcessProgressHandler(double percentComplete);
    
        public event ReallyLongProcessProgressHandler ProgressUpdate;
    
        private void UpdateProgress(double percent)
        {
            if (this.ProgressUpdate != null)
            {
                this.ProgressUpdate(percent);
            }
        }
    
        public void AVeryLongTimedFunction()
        {
            //Do something AWESOME
            List<Item> items = GetItemsToProcessFromSomewhere();
            for (int i = 0; i < items.Count; i++)
            {
                if (i % 50)
                {
                   this.UpdateProgress(((double)i) / ((double)items.Count)
                }
                //Process item
            }
        }
    }
    

    (2) Create a progress percentage field on AnotherClass. Occasionally interrogate this in your UI on a timer.

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

Sidebar

Related Questions

Currently I have a background thread that does some periodic heavy data management. Because
I currently have a complete cover background image. Here is the code: #back{ /*
I currently have the following CSS (called splash.css): html { background:url(splash.jpg) center no-repeat; background-size:auto
Background Currently, I am working on a Rails application. I have different products that
I have a website that I'm making that needs a background resizer. Currently, I
I have a .NET service that processes a queue on a background thread and
I am currently implementing cache. I have completed basic implementation, like below. What I
I call obackgroundworker.CancelAsync(); on a background worker currently doing some work in another thread
I have a long running operation which I am putting on a background thread
I have a simple app with the usual UI thread and a background worker,

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.