Solved

Simple Form Question

Posted on 2006-06-29
1
239 Views
Last Modified: 2010-04-17
I have a C# form with three objects.
A label, a textfield and a button.
When the button is pressed, it will run a for loop
run where i=0 until i=integer entered in text field.

I want to do it where if the number entered is large then after the button is pressed, the label will say "Running..." until it's done, then "completed." when it's done.

here's my code

            label2.Text = "Running.";
            for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
            {
            }
            label2.Text = "Completed.";

I know it's amateurish to do it this way cuz it doesn't work. It will freeze until it's done counting then label2.Text will just = "Completed."  And "running." is never seen.

How do I code it so it will say "Running" after the button is pressed and show "Completed" when it is completed?
0
Comment
Question by:flam79
1 Comment
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 250 total points
ID: 17014275
One approach would be to call Application.DoEvents() in your loop, this will process any windows messages that are waiting, try:

            label2.Text = "Running.";
            for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
            {
                    //... some processing here
                    Application.DoEvents();
            }
            label2.Text = "Completed.";
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pairs challenge 5 77
Path of Workbook 3 77
Non-recursive backtracking, using a stack 1 131
Turning python script into an applet 12 110
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

776 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