Wednesday, 11 September 2013

Why can't I asynchronously load ReportDocuments in Crystal

Why can't I asynchronously load ReportDocuments in Crystal

Using the code below we run into an issue with Crystal.
It seems ok to create ReportDocuments but not to load these simultaneously
(DESPITE the fact they are loaded from different PHYSICAL places)
It works fine with the lock in place, but remove that lock and it freezes!!
Does anyone have any ideas?
public static object fLock = new object();
private void button1_Click(object sender, EventArgs e)
{
int[] i = { 1, 2, 3 };
Parallel.ForEach<int>(i, j => CreateReportOutput(j));
}
private void CreateReportOutput(int j)
{
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new
CrystalDecisions.CrystalReports.Engine.ReportDocument();
**lock (fLock)**
rpt.Load(string.Format("C:\\_Temp\\temptabs\\reports{0:00}\\C_NOTES.RFM",
j));
rpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,
string.Format("C:\\_Temp\\temptabs\\output_{0}({1:00}).pdf",
DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff"), j));
}

No comments:

Post a Comment