Solved

C# While loop

Posted on 2014-12-10
15
98 Views
Last Modified: 2015-01-18
Hi,
Please see below code,
           int Results = 0;
           while (true)
           {
               Results = CheckFileCreate();
               if (Results == 1)
               {
                   break;
               }
           
           }

Open in new window

This code is working fine,But i need to show message for customer wait for finding file. after find its need to need to say found it. ANy idea greatly appriciate.thx
0
Comment
Question by:ukerandi
[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
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 9

Expert Comment

by:dustock
ID: 40492668
In your if statement for results == 1 add

               if (Results == 1)
               {
                   MessageBox.Show("Found file");
                   break;
               }

Open in new window

0
 
LVL 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
ID: 40493118
int Results = 0;
           while ( Results == 0)
           {
               Results = CheckFileCreate();      
            // when Results changes to 1, loop is terminated.  
           }
0
 
LVL 10

Author Comment

by:ukerandi
ID: 40496175
I just simple message show to wait
How to do that
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40496231
MessageBox.Show("Now it is starting the While Loop");
int Results = 0;
           while ( Results == 0)
           {
               Results = CheckFileCreate();       
            // when Results changes to 1, loop is terminated.   
           }
MessageBox.Show("Finished the While Loop");

Open in new window

0
 
LVL 10

Accepted Solution

by:
ukerandi earned 0 total points
ID: 40497316
i try using this(MessageBox.Show("Wait...."); but its waiting for user click on OK button,
I don't want to allow to user to click any button,
JUST want to show to client , wait until this process finish.
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40497518
Add a label control named lblMessage where you want your message to be displayed. and revise the code as shown below:
int Results = 0;
           while ( Results == 0)
           {
               Results = CheckFileCreate();       
            // when Results changes to 1, loop is terminated.  
           lblMessage.Text = "Wait..."; 
           }
// optionally include this message box:
MessageBox.Show("Process is completed.");
lblMessage.Text = "";

Open in new window

0
 
LVL 10

Author Comment

by:ukerandi
ID: 40498218
This is happening form is loading
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40498252
Use it there in that case.
0
 
LVL 10

Author Comment

by:ukerandi
ID: 40508347
But its not working if you use message box user needs to click on, I need to without users involved show message
please wait.
if I use lblMessage.Text = "Wait...";
in the form load event its not display,becuase its load event, it will display after the form load

So any better idea
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40508374
int Results = 0;
           while ( Results == 0)
           {
               Results = CheckFileCreate();      
            // when Results changes to 1, loop is terminated.  
           lblMessage.Text = "Wait...";
            this.Refresh();
           }
// optionally include this message box:
MessageBox.Show("Process is completed.");
lblMessage.Text = "";
this.Refresh();
0
 
LVL 10

Author Comment

by:ukerandi
ID: 40508395
no its not display,beucase its in the FORM LOAD EVENT
Any idea appriciate.Thx
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40508396
This is my last input, I hope it works for you.

lblMessage.Text = "Wait...";
int Results = 0;
           while ( Results == 0)
           {
               Results = CheckFileCreate();      
            // when Results changes to 1, loop is terminated.  
           }
// optionally include this message box:
MessageBox.Show("Process is completed.");
lblMessage.Text = "";
0
 
LVL 9

Expert Comment

by:dustock
ID: 40509067
It sounds like your looking for more of a splash screen.  

create a new form
set the FormBorderStyle property to None
Add a label to the form that says "Please Wait" or what ever you want it to say
Set the StartPosition to CenterScreen
Set ShowInTaskbar to False

Back in your main form
Add a using statement for threading
using System.Threading;

Open in new window


under the main method add the following code

        public void SplashScreen()
        {
            Application.Run(new Form2()); //where Form2 is the name of your splash screen form
        }

Open in new window


In the main method you'll want to create a new thread and start it to bring up your splash screen

        public Form1()
        {
            Thread t = new Thread(new ThreadStart(SplashScreen));
            t.Start();
            Thread.Sleep(5000); //set this to however long you want the splash screen up
            InitializeComponent();
            t.Abort();
        }

Open in new window


Then when your main form loads, you could put something in a label to state if the file was found our not, or a message box if you don't mind having the user click a button.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40526813
no its not display,beucase its in the FORM LOAD EVENT
Any idea appriciate.Thx


Have you tried moving your code to Shown event instead of load?
0
 
LVL 10

Author Closing Comment

by:ukerandi
ID: 40556014
good
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

687 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