在我的 WPF 应用程序代码中,我收到以下警告:
CA1001 Types that own disposable fields should be disposable Implement IDisposable on 'MainWindow' because it creates members of the following IDisposable types: 'BackgroundWorker', 'DataTable'. If 'MainWindow' has previously shipped, adding new members that implement IDisposable to this type is considered a breaking change to existing consumers. yesMonitor MainWindow.xaml.cs 38
主窗口代码:
public partial class MainWindow : Window
{
// Some code..
}
出现这些警告的原因是什么?
最佳答案
忽略此警告是安全的。
Backgroundworker 和 DataTable 都出于正式原因实现了 IDisposable,它们实际上并不需要它。
此外,您的 MainWindow 具有(定义)应用程序的生命周期,因此无论如何都不会有资源泄漏。
如果您想要形式上正确并遵守所有规则,那么只需将 IDisposable 添加到您的 MainWindow 类中。有一个片段。
关于c# - WPF代码分析: CA1001 Types that own disposable fields should be disposable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30977812/