Windows上的新线程MDI表单加载事件... [英] new thread on windows MDI form load event ...

查看:101
本文介绍了Windows上的新线程MDI表单加载事件...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows应用程序,我在其中使用Crystal报表。该应用程序的第一份报告非常缓慢。所以我采用了一个技巧来使用新线程在MDI表单加载事件上预加载晶体引擎。



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 .

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();
        }





但是,它会在crystalReportViewer1.ReportSource = cryRpt;行返回错误像{跨线程操作无效:控制''从一个线程以外的线程访问它。}执行时。请建议我如何正确地完成这项工作请告诉我。谢谢



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

推荐答案

这不会起作用。你不能把任何控制操作代码放在启动(UI)线程的其他任何东西上。



我不知道你将如何让它工作在背景,因为你所做的一切都是控制相关的,必须留在UI线程上。



我根本不了解Crystal Reports,但是你可能想尝试在CR的对象模型中找到一些东西,它可以预先加载报告,而不会告诉控件执行它或将控件绑定到报表,直到它被加载为止。
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.


这篇关于Windows上的新线程MDI表单加载事件...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆