Dialog is repeated twice C # WPF

1

Good afternoon, greetings.

Lately I have had a problem with sampling a Dialog in a formload, I am currently using C # in conjunction with sql server and implemented the UI of my program with Mahapps.metro. My code is as follows:

 private async void formload(object sender, RoutedEventArgs e)
    {
        Title = "Menú Principal " + "(Sesión de: " + MainWindow.cuentalogueada + ")";
        notificaciones.ToolTip = "Tienes reportes pendientes";
        datagrid.IsReadOnly = true;
        bool estado = await conex.ocupado(this);
        if (estado == true && banderanotificaciones == false)
        { 
            await this.ShowMessageAsync("Tienes reportes pendientes", "Puedes corroborarlas en el botón de la esquina inferior derecha.");

        }
        else
            if (estado == false && banderanotificaciones == true || estado == false && banderanotificaciones == false)
        {
            notificaciones.Visibility = Visibility.Hidden;
        }


    }

Meanwhile, the busy function is inside a class, the procedure is as follows:

public async Task<bool> ocupado(MetroWindow ventana) 
    {
        bool ocupado = false;
        try
        {
            cmd = new SqlCommand("Select encargados from reportes where encargados like '" + '%' + MainWindow.cuentalogueada + '%' + "' and estado = 'Abierto' ",cn);
            lector = cmd.ExecuteReader();
            if (lector.Read())
                ocupado = true;
            else
            { }
            lector.Close();
        }
        catch (Exception Ex)
        {
            await ventana.ShowMessageAsync("Hubo un error grave en la base de datos: ", Ex.ToString());
            Application.Current.Shutdown(); 
        }
        return ocupado;
    }

Here's the problem; Whenever I log in to a user whose conditions comply with the previous ones, I am shown the dialog (all right here), however, it is always shown twice.

PS: I just used trace and I could see that it's because the formload is firing twice, no matter if it's asynchronous or not.

I would greatly appreciate your help, thank you.

    
asked by Aaron Custodio 24.06.2017 в 18:13
source

0 answers