• 0
Sign in to follow this  
jean maestrelli

Como abrir e fechar um form.showdialog dentro de uma thread.

Question

Pessoal, tenho um form com uma picturebox que contem um gif de loading.

Estou tentando fazer com que antes de executar um método ele exiba essa imagem de carregando e feche quando terminar.

ele até funciona mas em determinado momento conforme o uso ele me retorna o erro:

An unhandled exception of type 'System.Threading.ThreadAbortException' occurred in System.Drawing.dll

Additional information: O thread estava sendo anulado.

 

Public Class clsModoCarregando

        Dim FrmLoading As New Loading
        Dim trdelegate As New ThreadStart(AddressOf carregarFormLoading)
        Dim trd As New Thread(trdelegate)
   
        Private Sub carregarFormLoading()

            Try

                FrmLoading.ShowDialog()

            Catch ex As ThreadAbortException
                Thread.ResetAbort()
            End Try

        End Sub

        Public Sub ExibirLoad()

            If Not trd.IsAlive Then

                trd.Name = "threadCarregando"
                trd.IsBackground = True
                trd.Start()

            End If

        End Sub

        Public Sub FecharLoad()

                If trd.IsAlive Then

                    trd.Abort()
                    trd.Join()

                End If

        End Sub

    End Class
  
  
  'evento do botao pesquisar do form
      Private Sub btnPesquisar_Click(sender As Object, e As EventArgs) Handles btnPesquisar.Click
		 
  		Dim ModoCarregando As New Ambiente.clsModoCarregando
        
        If lstConsulta.Items.Count > 0 Then

			ModoCarregando.ExibirLoad()
            dtgPesquisa.DataSource = insPesquisa.pesquisar(lstConsulta, dtNomesPesquisa.Rows(0)("Tabela"))
            dtgPesquisa.DataMember = dtNomesPesquisa.Rows(0)("Tabela")
			ModoCarregando.FecharLoad()

        Else

            If txtValorPesquisa.Text = String.Empty Then

                MsgBox("informe o valor a ser pesquisado.", vbInformation)
                txtValorPesquisa.Focus()

            Else

                MsgBox("Adicione a consulta antes de pesquisar.", vbInformation)
                btnAdicionar.Focus()

            End If

        End If

    End Sub

 

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this