Solved

Closing initial Login Form from Program.cs

Posted on 2008-10-29
3
1,679 Views
Last Modified: 2013-12-17
Morning Experts,

I'm having a bit of a brain fart. I think there is something small that I'm missing yet need help.

So.. pretty simple scenario:
Windows form app, Login window, which should be closed once user is authorized and the actual MDI application is presented.

 I modified the Program.cs file for the Login form to be displayed before the main application comes up ( code below ).
The authentication works but the Login form doesn't go away unless I close it separately. The only way it works right now If I authenticate and then close the form by hitting the Cancel button.

Any suggestions ?
Thank you in advance.
static class Program

    {

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        [STAThread]

        static void Main()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);
 

            Login userLogin = new Login();
 

            while (!userLogin.UserIsAuthenticated && userLogin.LoginAttempts<3)

            {

                if (userLogin.ShowDialog() == DialogResult.Cancel)

                {

                    break;

                }

            }
 

            if (userLogin.UserIsAuthenticated)

            {

                Application.Run(new Main());

            }
 

            

        }

    }

Open in new window

0
Comment
Question by:techsuppoprt
  • 2
3 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22831348
I assume that login is a form ?

if (userLogin.UserIsAuthenticated)
            {
               Login.close();
                Application.Run(new Main());
            }
 
0
 
LVL 1

Author Comment

by:techsuppoprt
ID: 22832020
No,doesn't work.
That's the thing, it doesn't get to this "if (userLogin.UserIsAuthenticated)" block of code at all unless the form is closed or Canceled.

Any ideas ?
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 400 total points
ID: 22833133
Login userLogin = new Login();
DialogResult dr = new DialogResult ();

dr = userLogin.ShowDialog()

while (!userLogin.UserIsAuthenticated && userLogin.LoginAttempts<3 && dr.ShowDialog == DialogResult.OK)        
            {
                 userLogin.LoginAttempts++;
                 dr = userLogin.ShowDialog();
            }

if (userLogin.UserIsAuthenticated)
    Application.Run(new Main());
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now