C# 当它';生成的分部类中的

C# 当它';生成的分部类中的,c#,windows-services,dispose,C#,Windows Services,Dispose,我正在C#中创建一个windows服务,并且服务类的dispose方法在生成的分部类中实现 像这样: partial class Service { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null

我正在C#中创建一个windows服务,并且
服务
类的dispose方法在生成的分部类中实现

像这样:

partial class Service
{
    private System.ComponentModel.IContainer components = null;

    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
}

在这种情况下如何处理dispose?

如果要修改
dispose
实现,请将其从
designer.cs
复制到代码隐藏类。 它是
designer.cs
中少数几个需要修改的地方之一


Windows窗体类也是如此

仅当在垃圾收集器开始之前释放资源是有用的时,才处置对象。当服务被释放时,这样做是没有用的,GC会在一微秒后运行。在Designer.cs文件中找到的Dispose()方法实际上从未被调用,这是一个毫无用处的问题。很高兴知道,这是fxcop指出的一个问题,我的公司对这些事情过于教条。不管怎样,处理它会引起任何问题吗?如果这个方法从未被调用,我猜不会。