我正在用vb.net 2010和windows 7开发程序。我的项目中有水晶报告。现在,当我第一次显示报告时,它比再次打开报告花费了相当长的时间,这是因为水晶报告运行时引擎是从第一次加载的。如何在运行程序后立即运行crystal report运行时引擎,甚至在运行计算机后快速加载crystal report?
我已经和CR合作过很多次了。我找到的唯一方法是称之为虚假报告(正如有人在sap论坛上发布的那样)。制作一个函数,尝试调用"dummy.rpt",即并捕获异常。您需要在第二个线程中执行此操作,这样UI就不会冻结。
Public Sub LoadDummyReport()
'SAP suggests is better to load a dummy report at the first app excution using a thread or a background worker to get DLLs ready when calling your production reports.
Try
ReportClass.Generate("", "", "dummy", Nothing, "", "", "", "", "")
Catch ex As Exception
' This will fail because ReportClass will throw an ex. Dummy.rpt does not exist but will load the crystal dlls.
End Try
End Sub
在我的ReportClass中:
Try
rpt.Load(....)
Catch ex As Exception
If reportName <> "dummy" Then
Throw New Exception("ReportFileNotFound")
Else
Throw New Exception("DummyRPTLoaded") 'In case you need to catch the ex.
End If
End Try
然后您可以使用BackgroundWorker或Thread。