我认为如果可以在选择一次报表的话,我是不会选择水晶报表了。除了免费算是个优势吧。
如果你不幸采用了水晶报表,就会碰到这个问题。
我用了预加载和子线程处理,基本算是缓解了。
1.首先在系统初始化的时候
[STAThread]
static void Main(string[] args)
{
ReLoadReports();
}
/// <summary>
/// 预加载报表
/// </summary>
public static void ReLoadReports()
{
ThreadPool.QueueUserWorkItem(state => LoadCR());
}
public static void LoadCR()
{
ReportClass repdoc = new dr_PT();
//cache.Add("loadRC",repdoc);
repdoc.Load( repdoc.FullResourceName);
repdoc = new dr_TTHotel();
repdoc.Load(repdoc.FullResourceName);
repdoc = new dr_TTDV();
repdoc.Load(repdoc.FullResourceName);
repdoc = new dr_TTSeat();
repdoc.Load(repdoc.FullResourceName);
repdoc = new dr_PT58mm();
repdoc.Load(repdoc.FullResourceName);
repdoc = new dr_PT58mm2();
repdoc.Load(repdoc.FullResourceName);
repdoc = new dr_PT58mm3();
repdoc.Load(repdoc.FullResourceName);
}
我本来想用hashtable做个缓存。后面思考水晶报表第二次运行会相对快点,基本判定有缓存。查了下相关资料,MSDN看到以下代码
https://msdn.microsoft.com/zh-cn/library/ms227445(v=vs.90).aspx
public virtual ReportDocument CreateReport() { if (nonEmbeddedReportDocument == null) { nonEmbeddedReportDocument = new ReportDocument(); nonEmbeddedReportDocument.Load(reportFileName); } return nonEmbeddedReportDocument; }
ReportClass 继承自ReportDocument ,至于内建缓存如何缓存的没有太深究原理。
2.报表处理可以非UI线程处理。无需阻塞主线程。
所以在展示报表的时候我还是threadpool,代码就不上了。
3.其他性能问题的话,主要是加载数据量的问题了。这个根据业务自己控制下。
原文:http://www.cnblogs.com/yuanhuaming/p/4342782.html