ukerandi
asked on
C# While loop
Hi,
Please see below code,
Please see below code,
int Results = 0;
while (true)
{
Results = CheckFileCreate();
if (Results == 1)
{
break;
}
}
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I just simple message show to wait
How to do that
How to do that
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");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 = "";
ASKER
This is happening form is loading
Use it there in that case.
ASKER
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
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
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();
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();
ASKER
no its not display,beucase its in the FORM LOAD EVENT
Any idea appriciate.Thx
Any idea appriciate.Thx
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 = "";
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 = "";
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
under the main method add the following code
In the main method you'll want to create a new thread and start it to bring up your splash screen
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.
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;
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
}
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();
}
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.
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?
ASKER
good
Open in new window