提问人:RendonLs 提问时间:9/11/2020 更新时间:9/11/2020 访问量:115
CA1063 从类中删除终结器并将其添加到 dispose 为 false 的代码中
CA1063 Remove finalizer from class and add it in the code where disposing is false
问:
我一直在努力避免这个警告,我根据 CA1063 尝试并理解的是:正确实现 IDisposable 是终结器应该只包含 false 中的 Dispose 方法。其余的代码应该写在其他地方。我尝试实现 Microsoft 的示例,但是当我添加 Dispose 方法时,出现一个错误,指出 dispose 方法已经存在,唯一已经存在的 Dispose 在设计器中。是设计师在制造麻烦吗?
~TimerUpdate()
{
Dispose(false);
try
{
this.matlab = null;
this.command = null;
}
catch(Exception ex)
{
Console.WriteLine("Exception in " + this.GetType().Name + ".cs: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "(): " + ex.Message);
this.Dispose();
}
}
private void TimerUpdate_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
this.updateRateBox_ValueChanged(sender, e);
this.updateRateCAN_ValueChanged(sender, e);
this.matlab = null;
this.Dispose();
}
catch(Exception ex)
{
Console.WriteLine("Exception in " + this.GetType().Name + ".cs: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "(): " + ex.Message);
this.Dispose();
}
}
答: 暂无答案
评论
Dispose(false)
protected virtual Dispose(bool)
Dispose()
Dispose(true)
IntPtr
FileStream
Dispose()
_resource?.Dispose()