?
Solved

Simple Form Question

Posted on 2006-06-29
1
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project

718 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