Thread Problem

bghanim

Active member
Joined
Dec 5, 2006
Messages
40
Location
Abu Dhabi - UAE
Programming Experience
1-3
Hello All,
I have a thread in my application that tries to load a form and display it, but my problem is that the form appears for a some seconds then disappears. I think this is because of the thread is being killed, right? How can I fix this problem

VB.NET:
  Dim loadThread As New System.Threading.Thread(AddressOf loadReport)
  loadThread.Start()
VB.NET:
 Private Sub loadReport()
        Dim rpt As New ReportDocument
        Try
            rpt.Load(Me.repSource)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        For i As Integer = 0 To Me.maxParam - 1
            Dim paramPattern As New CrystalDecisions.Shared.ParameterValues
            Dim paramValue As New CrystalDecisions.Shared.ParameterDiscreteValue
            paramValue.Value = Me.paramTextBox(i).Text
            paramPattern.Add(paramValue)
            rpt.DataDefinition.ParameterFields(Me.paramLbl(i).Text).ApplyCurrentValues(paramPattern)
        Next
        Dim fr As New userDefRepViewFr
        fr.CrystalReportViewer1.ReportSource = rpt
        fr.Show()

        'Me.Panel1.Visible = False
    End Sub
 
Do fr.ShowDialog() instead
 
You shouldn't be showing the form in the worker thread. If building the report takes time then by all means do it in a worker thread, but you should then show the form in the UI thread.
 
Thank you all,
I solved the problem by raising an event when the thread finishes its work, and there was an event handler for this event i.e. it take the responsibilty of creating an instance of the report viewer form.

Regards,
Baha
 
If you raise an event from a different thread then the event handler is also invoked in other thread context. Same issues goes here.
 
Back
Top