水晶报表释放资源

发布时间 2023-10-26 11:07:54作者: fulllove

近期发现水晶报表生成多张pdf时会存在一开始没问题,生成几十张后就生成不了了,排查后发现是水晶报表资源满了,生成后没有释放资源,导致生成失败,然后加了以下代码就可以了

  /// <summary>
        /// 水晶报表资源释放
        /// </summary>
        /// <param name="reportDocument"></param>
        public void ReleaseReportResources(ReportDocument reportDocument)
        {
            // release unmanaged resources
            reportDocument.Close();
            reportDocument.Dispose();

            // release managed resources
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }