What is this error ? Disconnectedcontext

Asked

Viewed 58 times

2

Galera blz ?

I’m here programming for Windows Form with the language C# when I come across an error "Disconnectedcontext" .

Well let me explain how my program works, I have several Rms in one project, where I have to make the transition between these Rms, for example one form is the Login and the other is a "Lesson plan" for example.

In the transition from the form "Login" to the form "Lesson Plan" in the constructor "Lesson Plan" I get this exception.

Basically the instruction is as follows, when I click on the login button the system authenticates the teacher, soon after everything goes well (authenticated teacher), I pass an instruction where I instate a thread and I pass a method in it, to be able to close the Form "Login" for the opening of the other form "Lesson Plan".

Follow the picture : http://i.imgur.com/6WWnRn8.jpg

Follow below the codes :

1 - Click login button

    private void Btn_Entrar_Click(object sender, EventArgs e)
    {

        string login = txbLogin.Text;
        string senha = txbSenha.Text;

        if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(senha))
        {
            MessageBox.Show("Não pode haver campo(s) vazio(s)");
            return;
        }


        if (login.Contains("'"))
        {
            MessageBox.Show("Não é permitido usar caracteres no login");
            return;
        }
        if (senha.Contains("'"))
        {
            MessageBox.Show("Não é permitido usar caracteres '  na senha");
            return;


        }



         professor = new Professor();


        if ((professor.Codigo = professor.autenticarProfessor(login, senha))                   != null)
        {
            professor.bindProfessor(login, professor);    

            this.Close(); //Fecho esta tela
            this.Dispose(); //Dispose nela
            th = new Thread(abrirTela_Plano_Aula); //Abro uma nova linha de 
            th.SetApartmentState(ApartmentState.STA);
            th.Start();
        }
        else {

            MessageBox.Show("Dados incorretos");
            return;
        }
    }

2 - Method that opens the other form

    private void abrirTela_Plano_Aula()
    {
        Application.Run(new Plano_Aula(professor)); //Aqui chamo a nova tela

    }

3 - Builder Lesson Plan Here I make checks if the teacher has photo if he doesn’t have, I’ll go to the bank and get a picture for teachers without a photo

    public Plano_Aula(Professor professor)
    {
        this.professor = professor;
        InitializeComponent();
        //Foto professor logado
        imgProfessor.ImageLocation = professor.FotoProfessor;
        imgProfessor.SizeMode = PictureBoxSizeMode.StretchImage;

        if (string.IsNullOrEmpty(professor.FotoProfessor))
        {
            if (professor.Sexo == "M")
            {
                professor.FotoProfessor = new ConfigurarImagemSistema().getImg("fotoAlunoDesconhecido", "M", "chamada");
                imgProfessor.ImageLocation = professor.FotoProfessor;

            }
            else if (professor.Sexo == "F")
            {
                professor.FotoProfessor = new     ConfigurarImagemSistema().getImg("fotoAlunaDesconhecido", "F", "chamada");
                imgProfessor.ImageLocation = professor.FotoProfessor;

            }

        }
  • This exception occurs when you run the program outside of Visual Studio? And when you run outside the debugger?

  • Inside the visual studio.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.