I'm trying to export a report to pdf whilst opening and displaying the report to the user. This is causing a long delay before the user can do anything with the report view.
I have had a go at creating threads but get the following error message when I run the code below:
"Controls created on one thread cannot be parented to a control on a different thread"
Have I misunderstood thread usage?
I have had a go at creating threads but get the following error message when I run the code below:
"Controls created on one thread cannot be parented to a control on a different thread"
Visual Basic:
Private Sub CrystalReportViewer1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
Try
Select Case gintReportType
Case gconstReportMailShot
myReport = New repMailShot
myReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait
Case constReturns
' myReport = New repReturns
myReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait
End Select
myReport.SetDataSource(m_dsReportSource)
Dim thdCopyPDF As New Thread(AddressOf CopyToPDF)
Dim thdLoadReport As New Thread(AddressOf LoadReport)
thdLoadReport.Start()
thdCopyPDF.Start()
Catch objException As Exception
ShowError("Location: Class frmReports" & ControlChars.CrLf & ControlChars.CrLf & "Procedure: " & _
"CrystalReportViewer1_Load(ByVal sender As Object, ByVal e As System.EventArgs)" & _
ControlChars.CrLf & ControlChars.CrLf & "Error Text: " & objException.Message)
End Try
End Sub
Private Sub CopyToPDF()
myReport.ExportToDisk(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat, gstrServerArea & "Mailshot.pdf")
End Sub
Private Sub LoadReport()
Try
Me.CrystalReportViewer1.ReportSource = myReport
Me.CrystalReportViewer1.Zoom(75)
Catch objException As Exception
ShowError("Location: Class frmReports" & ControlChars.CrLf & ControlChars.CrLf & "Procedure: " & _
"LoadReport" & ControlChars.CrLf & ControlChars.CrLf & "Error Text: " & objException.Message)
End Try
End Sub
Have I misunderstood thread usage?