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

  • Home
  • SEARCH
  • 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 573443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:43:27+00:00 2026-05-13T13:43:27+00:00

I am trying to create a login form. The problem that I am having

  • 0

I am trying to create a login form. The problem that I am having is that the login process is taking too long and is locking up my GUI. I have read up on background worker, but I am still uncertain on how to have my program wait for the login process but not freeze my GUI. Here is my code to help explain it more.

Login.cs

 public partial class Login : Form
 {
    public delegate bool Authenicate(string account, string password,string type);
    public Authenicate authenicate;
    public Login()
    {
        InitializeComponent();
    }

    private void btnLogin_Click(object sender, EventArgs e)
    {
        if (txtAccount.Text == string.Empty)
        {
            MessageBox.Show("Must include account number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }
        if (txtPassword.Text == string.Empty)
        {
            MessageBox.Show("Must include password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }
        if (!authenicate(txtAccount.Text, txtPassword.Text,cmbType.Items[cmbType.SelectedIndex].ToString()))
        {
            return;
        }
        this.DialogResult = DialogResult.OK;
    }

    private void Login_Load(object sender, EventArgs e)
    {
        cmbType.SelectedIndex = 0;
    }

MainForm.cs

public partial class MainForm: Form
{
    Ex.Service myService=new Ex.Service();

    public MainForm()
    {
        InitializeComponent();
    }
    public bool Authenicate(string account, string password,string type)
    {
         try
         {
             //Login takes too long and locks up GUI
             //Maybe try background worker, but how to wait until
             //login is complete?
             myService.Login(account,password,type);
             return myService.IsLogin();
         }
         catch(Exception exception)
         {
             MessageBox.Show(exception.message);
         }
         return false;
    }

    private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        myService.Logout(); //Logout from service
        myService = null;
    }
}

Thank you for your time.

  • 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-13T13:43:28+00:00Added an answer on May 13, 2026 at 1:43 pm

    The general steps are:

    1. Add the Background Worker to your Login dialog
    2. Create an event handler for the Background Worker’s DoWork event that calls you authenticate delegate.
    3. In btnLogin_Click disable the Login dialog so the user cannot click login again while the back ground worker is running.
    4. In btlLogin_Click call the BackGround worker’s RunWorkAsync method to start the worker running.
    5. Create an event handler for the Background Worker’s RunWorkerCompleted event. In that event enable the LoginForm and either close the dialog if the login result was successful or display en error message.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.