How can I debug an issue with a wrapper class causing this.Close() to hang upon form loading?

121 Views Asked by At

I'm writing an application that has a login form show prior to launching the main application. If the form is not allowed to load (the form checks for existing credentials and validates them, if successful the form is closed in the form_load event) then the application continues along swimmingly. However, if those credentials don't exist or are not correct then the form finishes loading and presents itself as a login form for the user.

When the user enters their information they then click a submit button which triggers a round of validation identical to above and then closes.

The login form does close (visibly) but never returns a result to the main program.

Main:

    DialogResult result;
    using (LoginForm lf = new LoginForm())
        result = lf.ShowDialog();
    if (result == DialogResult.OK)
    {
        Application.Run(new LibraryForm());
    }
    else
    {
        Application.Exit();
    }

From the login form:

    
    private void loginMaterialButton_Click(object sender, EventArgs e)
    {
        if (usernameTextBox.Text == "")
        {
            MessageBox.Show("You must enter a valid sharepoint user email for authentification!");
        }
        else if (passwordTextBox.Text == "")
        {
            MessageBox.Show("You must enter a valid sharepoint password for authentification!");
        }
        else
        {
        if (UpdateCredentials())
        {
            try
            {
                CloseOut();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }

    private void LoginForm_Load(object sender, EventArgs e)
    {
        if (CheckExistingCredentials())
        {
            CloseOut();
        }
    }

    private void CloseOut()
    {
        this.DialogResult = DialogResult.OK;
        this.Close();
    }

I made a second barebones LoginForm with only standard winform components and it worked as expected, however I'm not sure what the best course of action is to determine what exactly is causing the login form to not return on close?

Here is the github link for the package I'm using to wrap the winform: https://github.com/leocb/MaterialSkin

1

There are 1 best solutions below

0
James Bradley On

Mystery solved:

https://github.com/leocb/MaterialSkin/issues/67

The issue is within this library, apparently something holds up the return of DialogResult when using the password characters in a ShowDialog form.