What is the best way to cleanup the resources used by a Crystal Reports ReportDocument object?(清理 Crystal Reports ReportDocument 对象使用的资源的最佳方法是什么?)
问题描述
我正在开发一个使用 Crystal Reports 进行报告的应用程序.它在 ReportDocument 对象中打开给定的报表,执行它需要执行的操作,然后关闭报表.
I am working on an application that uses Crystal Reports for the reporting. It opens a given report in a ReportDocument object, does what it needs to do and then closes the report.
using (var report = OpenReport(reportSourceInfo))
{
// Do stuff with the report
report.Close();
}
OpenReport 方法对源文件进行一些验证并返回一个打开的 ReportDocument 对象.
The OpenReport method does some validation of the source file and returns an open ReportDocument object.
测试表明,此代码执行了预期的操作,并且似乎没有任何问题.我真正寻求建议的问题是,当我对报告项目进行代码分析 (CA) 构建时,我收到以下 CA 消息:
Testing has shown that this code does what it's meant to do and appears to have no issues. The problem I'm really after advice on is when I do a code analysis (CA) build of the reporting project, I get the following CA message:
CA2202:Microsoft.Usage:对象report"可以在方法CrystalReportingProvider.ReportExecute(ReportSourceInformation)"中多次处理.为避免生成 System.ObjectDisposedException,您不应在一个对象上多次调用 Dispose.
CA2202 : Microsoft.Usage : Object 'report' can be disposed more than once in method 'CrystalReportingProvider.ReportExecute(ReportSourceInformation)'. To avoid generating a System.ObjectDisposedException you should not call Dispose more than one time on an object.
现在显然我可以更改代码,所以我不会收到这个 CA 警告,但我的问题是我应该这样做吗?
Now obviously I can change the code around so I don't get this CA warning, but my question is should I?
Crystal Reports ReportDocument.Close() 方法是否可以正确处理资源清理?该消息似乎表明 Close 方法调用了 Dispose 方法,但这似乎并不正确.
Does the Crystal Reports ReportDocument.Close() method do everything to handle resource cleanup properly? The message seems to indicate that the Close method calls the Dispose method, but that just doesn't seem right.
任何建议将不胜感激.
推荐答案
嗯,根据this, "Close() ... 释放报告使用的内存."这表明 Close() 调用了 Dispose(),因此同时使用 using 语句和 Close() 将是多余的.
Well, according to this, "Close() ... release[s] the memory that is used by the report." That would indicate that Close() calls Dispose(), so it would be redundant to have both a using statement and Close().
这篇关于清理 Crystal Reports ReportDocument 对象使用的资源的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:清理 Crystal Reports ReportDocument 对象使用的资源的最佳方法是什么?
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30