1455376 - How to launch reports on two separate threads

SAP Knowledge Base Article - Public

1455376 - How to launch reports on two separate threads

Symptom

Not able to launch two reports from one application at the same time

Cause

Using CrystalReportsDocument.Load or any other Crystal Reports APIs for .NET to launch a report is a sequential process

Resolution

  • Use two separate threads
Public Class Form1
 
    Private rpt1 As ReportDocument
    Private rpt2 As ReportDocument
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim viewer As CrystalDecisions.Windows.Forms.CrystalReportViewer
 
        ' pre-load reports 1 and 2
        rpt1 = New ReportDocument
        rpt2 = New ReportDocument
        rpt1.Load(Application.StartupPath & "\report1.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
        rpt2.Load(Application.StartupPath & "\report2.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
 
        viewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer()
        viewer.ReportSource = rpt1
        viewer.ShowLastPage()
        rpt1 = viewer.ReportSource
 
        viewer.ReportSource = rpt2
        viewer.ShowLastPage()
        rpt2 = viewer.ReportSource
 
        viewer.Dispose()
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim t As Thread
 
        t = New Thread(AddressOf PrintRpt1)
        t.Start()
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim t As Thread
 
        t = New Thread(AddressOf PrintRpt2)
        t.Start()
    End Sub
 
    Private Sub PrintRpt1()
        ' print report 1
        rpt1.PrintToPrinter(1, True, 0, 0)
    End Sub
 
    Private Sub PrintRpt2()
        ' print report 2
        rpt2.PrintToPrinter(1, True, 0, 0)
    End Sub
End Class


Keywords

Forum thread , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

Crystal Reports 2008 V1