首页 > 解决方案 > LocalReport 有时会在渲染时挂起

问题描述

在 C#/WPF 应用程序中生成 RDLC 报告时,有时它会挂起渲染(render方法调用不返回)。

报告数据来自 C# 对象(预先用 PostgreSQL 数据库中的数据填充),因此此问题与 SQL 无关。

我想知道:

  1. 我怎样才能找出原因?
  2. 有什么方法可以让用户在报告生成挂起时终止它?

将报告生成嵌入到一个using块中(如ReportViewer 渲染在某些执行后挂起服务器中所见)并没有解决问题。

using (LocalReport report = new LocalReport())
{
    report.ReportPath = @"C:\Path\To\MyReport.rdlc";

    // Get the report data from db and fill it into MyReportData object.
    MyReportData data = CreateReportData();

    ReportDataSource headerDataSource = new ReportDataSource();
    headerDataSource.Name = "HeaderDataSet";
    headerDataSource.Value = data.Header;
    report.DataSources.Add(headerDataSource);

    // Add more data sources ...

    // No report parameters are being used

    report.Refresh();

    pdfData = report.Render("PDF"); // here it hangs sometimes
}

如上所述,render-call 有时会挂起。杀死应用程序并再次生成完全相同的报告后,它就可以工作了。

标签: c#rdlc

解决方案


推荐阅读