Solved

Closing initial Login Form from Program.cs

Posted on 2008-10-29
3
1,681 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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