Displaying progress during execution

Posted on 2004-11-21
Last Modified: 2009-06-27
Hi, I have a small app that updates a bunch of database records. The problem is that this process takes a long time and I'd like to display a simple textbox to show the current percentage complete.

At the moment, I update this textbox in the method that is executing, then call 'this.Invalidate()' then 'this.Refresh()' and it seems to work. Problem I have is when the app is resized or loses focus or whatever, it stops updating. What is the correct way to implement this type of scenario?
Question by:Statiscuro
    LVL 22

    Expert Comment

    LVL 11

    Accepted Solution

    Are u trying to refresh  the textBox on a different thread.
    If yes then use Invoke method of ur form to refresh.
    As refreshing from other threads is a problem.

    e.g. from ur thread use this code

    // Define the delegate
    delegate void delCallRefresh(object pObject);

    // From ur thread use these lines of code
    int percentage = 10;
    object[] objArray ={percentage};
    // here this is reference to ur form
    this.Invoke(  new delCallRefresh(this.RefreshTextBox),objArray);

    // Define this method in form and refresh the textbox in this method
    private void RefreshTextBox(object pObject)
          int percentage = (int)pObject;
          textBox1.Text = percentage.ToString();

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now