I have an application, which uses a method to create reports including a SciChart-Control. This does work both in WPF and Console applications. But when I needed to create such report automatically in a windows service, the service just seems to hang upon calling the report-method.
Used packages:
- SciChart, testet with Version 6 and 7
- Microsoft.ReportViewer.WinForms, Version 10.0.40219.1
I figured, that it doesn't matter if I actually include the SciChart-Control in the report. What matters is, if I create an instance of the SciChart-Control before printing the report. The LocalReport.Render() method seems to block further execution then.
I created a minimal working example, where
- SciChartControl is an blank WPF control, only containing a SciChartSurface-Element
- Report1.rdlc is a blank report, containing just a textbox-element.
public class Test
{
private const string PathOfReport = @"Path\to\report\Report1.rdlc";
private const string OutputPath = @"Path\to\output";
private const string DeviceInfo = "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>";
public static void TestReport(string outputName, bool instantiateSciChart)
{
var t = new Thread(() =>
{
if (instantiateSciChart)
_ = new SciChartTestControl();
byte[] data = DoRenderReport();
File.WriteAllBytes(@$"{OutputPath}\{outputName}.pdf", data);
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
private static byte[] DoRenderReport()
{
LocalReport localReport = new() { ReportPath = PathOfReport };
// Blocks both at GetParameters() and localReport.Render()
//localReport.GetParameters();
return localReport.Render("PDF", DeviceInfo);
}
}
And I call it in Startup-Method of service:
Test.TestReport("AutoPrintTest_Service", instantiateSciChart: true); // or false to succeed
I create and test the service using sc create
.
I expect that a pdf-file is generated in the output-path, but this does only work if no SciChart is instantiated. Otherwise the service hangs. When stopping the service, a process of the service keeps actually running, which needs to be terminated.
Maybe I am missing something, like some configuration for the windows service. Any help is very appreciated, thanks a lot!