调用页面里这样写:
protected void Page_Load(object sender, EventArgs e)
{
Session["YmXx_Cz"] = "7";
Thread.Sleep(1000);
Thread td = new Thread(new ThreadStart(this.LoadCR));
td.Start();
}
private void LoadCR()
{
if (Cache["loadCR"] == null)
{
ReportDocument repdoc = new ReportDocument();
repdoc.Load(this.Server.MapPath("~/CrystalReport").ToString() + "/CrystalReport_ScXx_Tj.rpt");
Cache.Insert("loadRC", repdoc);
}
}
然后在报表页面这样写:
ReportDocument repdoc;
if (Cache["loadCR"] != null)
repdoc = Cache["loadCR"] as ReportDocument;
repdoc.SetDataSource(ds.Tables["SrXx_Tj"]); CrystalReportViewer1.ReportSource = repdoc;
CrystalReportViewer1.DataBind();
con.Close();
思路是调用页面在1秒后响应线程,启动线程并调用进缓存中,这样线程在用户不察觉的情况下预加载进原始报表,以后的用户再进入时,就直接从Cache中调用了。我是这样的思路,求证这样解决可以吗?
protected void Page_Load(object sender, EventArgs e)
{
Session["YmXx_Cz"] = "7";
Thread.Sleep(1000);
Thread td = new Thread(new ThreadStart(this.LoadCR));
td.Start();
}
private void LoadCR()
{
if (Cache["loadCR"] == null)
{
ReportDocument repdoc = new ReportDocument();
repdoc.Load(this.Server.MapPath("~/CrystalReport").ToString() + "/CrystalReport_ScXx_Tj.rpt");
Cache.Insert("loadRC", repdoc);
}
}
然后在报表页面这样写:
ReportDocument repdoc;
if (Cache["loadCR"] != null)
repdoc = Cache["loadCR"] as ReportDocument;
repdoc.SetDataSource(ds.Tables["SrXx_Tj"]); CrystalReportViewer1.ReportSource = repdoc;
CrystalReportViewer1.DataBind();
con.Close();
思路是调用页面在1秒后响应线程,启动线程并调用进缓存中,这样线程在用户不察觉的情况下预加载进原始报表,以后的用户再进入时,就直接从Cache中调用了。我是这样的思路,求证这样解决可以吗?
最好是先找到为啥慢的原因, 是在取数据慢那里出了问题,还是在绘制报表控件那里出了问题。我感觉,应该是在绘制报表控件, 在客户端来看,所有东西都是HTML的,要把一套报表显示出来,
先要把报表的框架画出来,然后填充数据。以上都是猜测,加入我的猜测是对的话,那最耗时的应该是在绘制报表那里慢,采用您的方案,好像解决不了问题...
耗时过程主要在拉取数据后,分页、公式、样式等处理。这些生成rpt后即完成。另外CrystalReportViewer1.DataBind(); 这句去掉看看。