Solved

Crystal Reports Viewer Slow on First Load but Fast After

Posted on 2009-07-05
4
3,999 Views
Last Modified: 2012-05-07
I find the Crystal Reports Viewer (winforms) very slow to load the first time it is called. After that it is much faster.

I have tried to open a form with the viewer invisibly, but can't get this to work in CSHARP.  If I do this visibly when then Main Menu loads, it solves the problem, i.e., the "first" time a report is run the viewer comes up instantly.

Have also tried creating an instance of a form with a viewer, NOT showing the form, but only calling a refresh on the viewer.  I don't see much timing difference with this approach.

I noticed another posting on this topic that suggests opening a Crystal report in another thread, but I could not get this code to work in CSHARP.
0
Comment
Question by:hertzgordman
  • 2
  • 2
4 Comments
 

Author Comment

by:hertzgordman
ID: 24780193
Here is my code for just creating an instance of the form and refreshing the viewer:

private void OpenReportViewerInvisible()
        {


            // Open Report for USER
            MonthReport1Form MyForm = new MonthReport1Form();

            {
                try
                {

                    // UserName
                    MyReports MyReportsClass = new MyReports();
                    string UserName = MyReportsClass.GetWindowsUser();

                    MyForm.FormParam_UserName = UserName;
                    MyForm.FormParam_ReportFileName = @"C:\Database\LoanTrack\LoanWithDeferredInterest.rpt";

                    this.Cursor = Cursors.WaitCursor;

                    // Refresh the viewer
                    MyForm.MonthReport1FormViewerRefesh();

                    // Cursor off
                    this.Cursor = Cursors.Default;

                    // Close the form
                    MyForm.Close();


                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

        }
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 24781186
I have this code that I never tried to preload CR assemblies:

> > Is it possible to preload assemblies before they are called?  Each
> > time the first report in my app runs, it takes 10-15 secs while it
> > loads the appropriate assemblies, after that any report that is run
> > appears immediatly.

> Here you go...

> ' load up crystal when the app starts up.
> ' use a separate thread since its such a pig.
>             TraceWriteLine("starting Crystal Reports Thread")
>             myTimer = New FunctionTimer("load crystal")
>             Dim t As New Thread(AddressOf LoadCrystal)
>             t.Priority = ThreadPriority.BelowNormal
>             t.Start()
>             myTimer.EndTimer()
>             TraceWriteLine("...thread started")


> ' here's the code to load up a dummy report.
> ' this seems to load up and keep everything in memory throughout the
> life of the app.

>     Public Sub LoadCrystal()
>         crReport = New ReportDocument

>         Try
>             ' Need to preload crystal engine so the reports will print
> quickly throughout the rest of the application.
>             ' This report is not used, it is just loaded.  Testing so
> far 12/23/04 has not shown any
>             ' problems such as memory or print errors.
>             crReport.Load(CrystalReportFolder & "rptBlank.rpt")

>         Catch ex As Exception
>             DisplayException(ex, "Error: Could find the startup
> Crystal Report named 'rptBlank.rpt'." & _
>                vbCrLf & "If you are a new user, you may lack Server
> permissions to read this directory and file: " & CrystalReportFolder & 
> "rptBlank.rpt" & _
>                vbCrLf & "Or the report may have been deleted or
> corrupted.  Please Call IT.  [EJS0412311300]")
>         End Try
>     End Sub

0
 

Author Comment

by:hertzgordman
ID: 24781494
I did try the code and I am not sure if it speeding things up or not.

Also found a way to load the viewer on a "hidden" form by setting the forms opacity to 0%:

private void OpenReportViewerInvisible()
        {


            // Open Report for USER
            MonthReport1Form MyForm = new MonthReport1Form();

            {
                try
                {

                    // UserName
                    KingSettReports MyReportsClass = new KingSettReports();
                    string UserName = MyReportsClass.GetWindowsUser();

                    MyForm.FormParam_UserName = UserName;
                    MyForm.FormParam_ReportFileName = @"C:\Database\LoanWithDeferredInterest.rpt";

                    this.Cursor = Cursors.WaitCursor;

                    // Show the form with no opacity
                    MyForm.Opacity = 0;
                    MyForm.Show();

                    // Refresh the viewer
                    MyForm.MonthReport1FormViewerRefesh();

                    // Cursor off
                    this.Cursor = Cursors.Default;

                    // Close the form
                    MyForm.Close();

                    // MessageBox.Show("Form loaded");



                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

        }
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 500 total points
ID: 24781761
the trick is to load a small dummy report when the application starts to load CR assemblies in memory.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question