尽管之前已在此处讨论过主题,但建议的解决方案似乎不起作用..
我的表单应用程序中有一个按钮单击回调方法,它显示了一个文件夹选择器对话框:
private void ButtonSelectReporterFolderClick(object sender, EventArgs e)
{
using (var dialog = new FolderBrowserDialog()) // causes warning
{
if (dialog.ShowDialog() == DialogResult.OK)
{
this.boxReporterFolderPath.Text = dialog.SelectedPath;
}
}
}
这会产生一个警告:
CA2000: Microsoft.Reliability : In method 'MainWindow.ButtonSelectReporterFolderClick(object, EventArgs)', object '<>g__initLocal' is not disposed along all exception paths. Call System.IDisposable.Dispose on object '<>g__initLocal' before all references to it are out of scope.
我还尝试使用try
-finally
块甚至调用 dialog.Dispose 没有任何块,一切都无济于事 - 警告仍然存在,始终在初始化行。