C# 多线程RDLC报告未刷新

C# 多线程RDLC报告未刷新,c#,parallel-processing,rdlc,C#,Parallel Processing,Rdlc,大师 我们正在.NET4.0中开发一个WinForms应用程序,它使用RDLC控件生成PDF报告。由于生成报告需要很多时间,我们决定对每个报告执行并行。。使用下面的代码,它会为第一条记录生成PDF,然后系统就挂起了。。一定要帮助我们 public void generatereport() { button1.Enabled = false; button4.Enabled = false; DataTab

大师 我们正在.NET4.0中开发一个WinForms应用程序,它使用RDLC控件生成PDF报告。由于生成报告需要很多时间,我们决定对每个报告执行并行。。使用下面的代码,它会为第一条记录生成PDF,然后系统就挂起了。。一定要帮助我们

 public void generatereport()
        {
            button1.Enabled = false;
            button4.Enabled = false;
            DataTable dtBranch = new DataTable();
            dtBranch = getBranchNo(); -- we might get around 300 rows here

            try
            {
                Parallel.ForEach(dtBranch.AsEnumerable(), drow =>
                   {
                       // Shows the ReportData along with the branch code
                        reportdate = drow["reportdate"].ToString();
                       string branchName = drow["BranchNo"].ToString();
                        ProcessReport(branchName);
                   });
                  reportViewer2.Visible = false;
            button1.Enabled = true;
            button4.Enabled = true;
            lblMsg.Text = "Branch Summary Generated at '" + @fullpath + "'";
            }
            catch (AggregateException e)
            {
                //Console.Write(e.Data + e.Message);
                //Console.ReadLine();
            }

        }

        private void ProcessReport(string branName)
        {
            if (reportViewer2.InvokeRequired)
            {
                ProcessReportCallBack d = new ProcessReportCallBack(ProcessReport);
                Invoke(d, new object[] { branName });
            }
            else
            {
                log.Debug("branch" + DateTime.Now.ToString());
                DataTable dt = new DataTable();
                dt = getReportOrderNoBasedonBranchID(branName);//Get all the report order no as per the branch id

                    this.sp_getReportOrderNoTableAdapter.Fill(this.getRptNo.sp_getReportOrderNo, branName);
                    this.reportViewer2.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer2_Subreport1);
                    this.reportViewer2.Clear();
                    this.reportViewer2.ProcessingMode = ProcessingMode.Local;
                    this.reportViewer2.LocalReport.ReportPath = @"Master.rdlc";
                    this.reportViewer2.Refresh();

                    Savepdf("reportViewer2", branName + "_" + reportdate);

            }
    }
在保存PDF中,我们将生成PDF报告

byte[] bytes = null;

                bytes = reportViewer2.LocalReport.Render(
                "PDF", null, out mimeType, out encoding,
                 out extension,
                out streamids, out warnings);
                filename = BranchName + '_' + "Summary" + ".pdf";

                using (FileStream fs = new FileStream(@fullpath + '\\' + filename, FileMode.Create))
                {
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Close();
                }
                bytes = null;

请提供您的反馈

RDLC
已呈现到
ReportViewer
时,您不需要将示例代码导出为PDF,请尝试从ReportViewer控件的
工具栏中查找此图标


编辑


如果我理解您的问题,您可以通过
ReportViewer
导出为PDF而无需任何代码,我有700多行,并使用
export to PDF
ReportViewer控件
导出为PDF。这只需要几秒钟。您能分享一下示例代码吗?我们的主报告中有子报告,我有子报告事件处理程序,其中我从主rdlcI传递参数,我必须做同样的事情。我需要使用rdlc生成大量PDF,并且必须使其具有多线程。你能展示你的最终代码吗?我试着以编程的方式做ti。没有用户干预,我自己生成一份报告,它本身大约需要30-45秒…所以需要以视差方式生成PDF
public void Save(ReportViewer viewer, string savePath)
{
    byte[] Bytes = viewer.LocalReport.Render("PDF", "", null, null, null, null, null);

    using (FileStream Stream = new FileStream(savePath, FileMode.Create)) {
        Stream.Write(Bytes, 0, Bytes.Length);
    }
}