?
Solved

Crystal Reports Viewer Slow on First Load but Fast After

Posted on 2009-07-05
4
Medium Priority
?
4,125 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 2000 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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 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