Application.Run

G

Guest

I am developing a windows form with a login screen.Once a user succesfully
logs in,I want to close the login screen and run the main application.

I dont want to use show dialog box.I would like to use application.run for
both the forms.

Please let me know what is a good way to do it.
Any help is highly appreciated.

Thanks
 
G

Guest

In order to open the second form using the Application.Run, once the user
successfully logs in, exit from the thread on which login form is running
using
'Application.ExitThread()' and spawn a new thread. The thread will be
spawned using System.Threading.Thread. Now another form can be run using
Application.Run on newly spawned thread.

Sample Code:
The following code for the button click event of the 'login button' enables
the user to log in and run the second form using Application.Run as well.


System.Threading.Thread td;
private void button1_Click(object sender, EventArgs e)
{

if(this.textBox1.Text=="a" && this.textBox2.Text=="a")
{


Application.ExitThread();
Thread td = new Thread(new ThreadStart(ss));
td.Start();

}

}
protected void ss()
{
MessageBox.Show("new thread is running");
Application.Run(new Form2());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top