Search code examples
vb.netperformancecrystal-reportsload

VB.Net crystal report takes time to load


I am developing program with vb.net 2010 with windows 7. I have crystal reports in my project. Now when I display the report for the first time it takes quite long time than opening the report again, and that is because crystal report run time engine is loaded from the first time. How can I run the crystal report run time engine immediately after running the program or even after running the computer itself to load crystal report fast?


Solution

  • I've worked with CR many times now. The only way I've found is to call a dummy report (as someone posted on sap's forum). Make a function that try to call "dummy.rpt" i.e. and catch the exception. You'll need to do this in a second thread so the UI doesn't freeze.

    Public Sub LoadDummyReport()
        'SAP suggests is better to load a dummy report at the first app excution using a thread or a background worker to get DLLs ready when calling your production reports.
        Try
            ReportClass.Generate("", "", "dummy", Nothing, "", "", "", "", "")
        Catch ex As Exception
            ' This will fail because ReportClass will throw an ex. Dummy.rpt does not exist but will load the crystal dlls.
        End Try 
    End Sub
    

    And in my ReportClass:

    Try
        rpt.Load(....)
    Catch ex As Exception
        If reportName <> "dummy" Then
             Throw New Exception("ReportFileNotFound") 
        Else
             Throw New Exception("DummyRPTLoaded") 'In case you need to catch the ex.
        End If
    End Try
    

    Then you could use a BackgroundWorker or a Thread.