Solved

Crystal Reports Viewer Slow on First Load but Fast After

Posted on 2009-07-05
4
3,904 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
Comment Utility
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 69

Accepted Solution

by:
Éric Moreau earned 500 total points
Comment Utility
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
Comment Utility
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 69

Assisted Solution

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now