Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:33:30+00:00 2026-05-26T20:33:30+00:00

My application has a restricted access. I have a user/password box in a small

  • 0

My application has a restricted access. I have a user/password box in a small dialog, and when logged-in, I’m loading a very big form with a tons of controls and several big grids. The whole InitializeComponent() take almost 10 secs to load without any data.

The issue is : how I could pre-run the Form constructor() while users are filling the two login fields ? If user is very slow and need >10 secs to complete authentification, it will be as quick as a wink to show application.

I think it is possible because it is two seperates top level windows, but I have no idea how to implement it. BackgroundWorker, new Thread, … ? Any clue ?

SOLUTION :

Following Eamonn McEvoy’s example, I added some fixes about my prerequesites : I wanted to show only login dialog, and if logged successful, I show the big form.

[STAThread]
static void Main()
{
    Launcher context = new Launcher();
    Application.Run(context);
}


public class Launcher : ApplicationContext
{
    private BigForm _bigForm;
    private Thread _loginThread;
    private SynchronizeLogin _sharedLogin;

    public class SynchronizeLogin
    {
        private bool _waited = false;
        public bool IsInitialized
        {
            get // loginform should wait before closing until return true
            {
                lock (this)
                {
                    return _waited;
                }
            }
            set // must be set when bigform is initialized
            {
                lock (this)
                {
                    _waited = value;
                }
            }
        }

        private DialogResult _logged = DialogResult.None;
        public DialogResult loginResult
        {
            get // wait until loginform close
            {
                lock (this)
                {
                    if (_logged != DialogResult.None)
                        return _logged;
                    else
                    {
                        Monitor.Wait(this);
                        return _logged;
                    }
                }
            }
            set // set from loginform when closing
            {
                lock (this)
                {
                    _logged = value;
                    Monitor.Pulse(this);
                }
            }
        }
    }

    public Launcher()
    {
        // sync obj between forms
        _sharedLogin = new SynchronizeLogin();
        _loginThread = new Thread(new ThreadStart(LaunchLogin));
        _loginThread.Start();

        // first form
        _bigForm= new BigForm(_sharedLogin);
        _bigForm.Closed += new EventHandler(OnFormClosed);

        // notify login thread that the main one is ready
        // from now, the login form should be near closing
        _sharedLogin.IsInitialized = true;

        WaitLogon();
    }

    private void WaitLogon()
    {
        if (_sharedLogin.loginResult == DialogResult.OK)
        {
            _bigForm.LoginSuccessful(); // read and use auth session
            _bigForm.Show();
        }
        else
        {
            // escape on user login form
            // (other exit calls are not working in ctor)
            Environment.Exit(42);
        }
    }

    private void LaunchLogin()
    {
        // ask user
        LoginDialog _loginForm = new LoginDialog (_sharedLogin);
        _sharedLogin.loginResult = _loginForm.ShowDialog();

        // userlogin form closed
        // end only current thread
        Application.ExitThread();
    }

    private void OnFormClosed(object sender, EventArgs e)
    {
        // big form closed
        // end ApplicationContext globally
        base.ExitThread();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:33:30+00:00Added an answer on May 26, 2026 at 8:33 pm

    You could create your login window in a new thread from your main windows constructor

    using System.Threading;
    
    private AuthSession _authSession;
    
    public MainWindowConstructor()
    { 
        Thread loginThread = new Thread(new ThreadStart(Login());
        loginThread.Start();
        //Continue initializing
    }
    
    private void Login()
    {
        LoginWindow loginWindow = new LoginWindow();
        _authSession = loginWindow.GetAuthSession();
        loginWindow.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client apllication that run in very restricted area - it has
Is possible to restrict access to my .NET DLL library? My application has more
My application has a need to let the user choose a date from a
My application downloads/creates some files which in turn has link from database, if user
I have a Web Application which has Global_Asax and a Custom Error Page. When
I have a status controller for reporting how my application is functioning. It has
My Jquery mobile application has a simple login page through which the user will
I have one requirement to fulfill. Actually when ever user Login into my application
I have a web application that has a configuration folder that houses multiple XML
I have a Rails 3 application that has Categories. A category can be administered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.