我正在使用Windows服务来生成有关2K报告的报告。我还使用TPL来提高性能。我观察到,在本地计算机上它可以正常运行40个报告,但在2K的UAT上不能正常工作,它会异常停止工作并启动Windows服务状态。系统事件查看器中没有事件日志条目(我假设我没有得到事件日志条目,因为服务状态已启动并且不会异常终止)
这是我的代码块。
foreach (pt_report report in reportCollection)
{
//do some db operation which takes around 1-2 min.
if(report.Status != Completed) //check for completion of report generation
{
Task generateReport = new Task(delegate
{
ScheduleMassReportGeneration(report); // This takes around 2-3 min more to generate pdf.
});
generateReport.Start();
//Problem #1 occurs (see below description).
}
}
我知道,异步任务启动时,我需要写点东西来挂接线程,以便检查执行状态。基于上面的代码,我对此没有任何控制,就像现在的孤儿一样。现在,我想对其进行控制,以便可以检查该线程/任务发生了什么并将适当的状态记录到db并重新运行这些任务。
PS:在ScheduleMassReportGeneration()
method()中编写了正确的日志记录,以跟踪在生成报告时发生的情况。但我没有发现任何错误或可疑的迹象。它只是滑走而没有任何痕迹。