Solved

Crystal Reports Viewer Slow on First Load but Fast After

Posted on 2009-07-05
4
3,978 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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