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

查看:273
本文介绍了什么是清理的最佳方式由水晶报表的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:对象'报告'可以处理比方法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?

请问水晶报表ReportDocument.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.

任何意见,将不胜感激。

Any advice would be appreciated.

推荐答案

那么,根据的这个,关闭()...发布[S]所使用的报表中的记忆。这将表明,关闭()调用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().

这篇关于什么是清理的最佳方式由水晶报表的ReportDocument对象使用的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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