文檔首頁>>Stimulsoft Reports.WinForms教程-2019>>【Stimulsoft Reports.WinForms教程】在線程中呈現(xiàn)報表
【Stimulsoft Reports.WinForms教程】在線程中呈現(xiàn)報表
【下載Stimulsoft Reports.Ultimate最新版本】
此示例顯示如何在線程中呈現(xiàn)報表,在線程中呈現(xiàn)報表是在后臺進(jìn)程中運(yùn)行的,為此,使用BackgroundWorker類:
private System.ComponentModel.BackgroundWorker backgroundWorker1; private void button1_Click(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); }
在backgroundWorker1_DoWork流程事件開始時,您可以卸載報表并連接數(shù)據(jù),還應(yīng)該訂閱已編譯的報表對象的Rendering事件:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { using (var stream = Assembly.GetExecutingAssembly(). GetManifestResourceStream("RenderInThread.Master-Detail-Subdetail.mrt")) { report.Load(stream); } DataSet data = new DataSet(); data.ReadXmlSchema("..\\..\\Data\\demo.xsd"); data.ReadXml("..\\..\\Data\\demo.xml"); report.RegData(data); report.IsRendered = false; report.Compile(); report.CompiledReport.Rendering += new EventHandler(CompiledReport_Rendering); report.Render(false); }
在CompiledReport_Rendering事件中更新表單上的文本——顯示StatusString屬性的值,完成線程工作后,在查看器中顯示報表:
void CompiledReport_Rendering(object sender, EventArgs e) { button1.Invoke((EventHandler)delegate { button1.Text = report.StatusString; }); } private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { report.Show(); }
示例代碼的結(jié)果如下圖所示: