This example shows how to render a report in the thread. Rendering the report in the thread is run in the background process. For this purpose the
BackgroundWorker
class is used:
private System.ComponentModel.BackgroundWorker backgroundWorker1;
private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
In the start of the
backgroundWorker1_DoWork()
process event, you can dload the report and connect data. Also you should subscribe to the
Rendering()
event of the compiled report object:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
using (var stream = Assembly.GetExecutingAssembly().
GetManifestResourceStream("RenderInThread.Master-Detail-Subdetail.mrt"))
{
report.Load(stream);
}
report.IsRendered = false;
report.Compile();
report.CompiledReport.Rendering += new EventHandler(CompiledReport_Rendering);
report.Render(false);
}
In the
CompiledReport_Rendering()
event update the text on the form - show a value of the
StatusString
property. After completion of the thread work, show the report in the viewer:
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();
}
In the screenshot below you can see the result of the sample code: