Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows application in which i am using a Crystal report . First report of the application is very slow . So i adopted a trick to preload the crystal engine on MDI form load event using a new thread .

C#
public TopAccoutsMDI(Form splashScreen)
        {
   InitialiseCrystalEngines();
}

private void InitialiseCrystalEngines()
        {            
            
            Thread thCRLoadAssemblies = new Thread(new ThreadStart(LoadCrystalAssemblies));  
            thCRLoadAssemblies.Priority = ThreadPriority.BelowNormal;
            thCRLoadAssemblies.IsBackground = true;
            thCRLoadAssemblies.Start();                               
            objSplashScreen.Refresh(); 
        }


 private void LoadCrystalAssemblies()
        {
            DataSet dtReportdataset = new DataSet() ;
            ReportDocument cryRpt = Reports.TRReportDocument.GetReportDocument("DummyReport");
            cryRpt.SetDataSource(dtReportdataset);
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();
        }


However , it returns an error at line "crystalReportViewer1.ReportSource = cryRpt;" like "{"Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on."}" on execution . please kindly suggest me how to get this work without error please advice me. thanks
Posted

1 solution

That's not going to work. You cannot put ANY control manipulating code on anything other that the startup (UI) thread.

I don't know how you're going to get this to work in the background at all because everything you're doing is control related and must stay on the UI thread.

I don't know Crystal Reports well enough at all, but you might want to try and find something in the object model for CR that can preload a report without telling the control to do it or binding the control to a report until after it's loaded.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Apr-14 13:23pm    
Agree, a 5. Also, I advise to get rid of MDI by all means. There are no real benefits in it, but a number if hassles, and ugly UI. Microsoft is trying to phase it out.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900