Solved

Simple Form Question

Posted on 2006-06-29
1
253 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

726 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