Solved

Crystal Reports Viewer Slow on First Load but Fast After

Posted on 2009-07-05
4
4,077 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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