清理 Crystal Reports ReportDocument 对象使用的资源的最佳方法是什么? [英] What is the best way to cleanup the resources used by a Crystal Reports ReportDocument object?

查看:35
本文介绍了清理 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 对象使用的资源的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆