Search code examples
c#windows-servicesdispose

How to handle dispose when it's in a generated partial class


I'm creating a windows service in C# and the dispose method for the Service class is implemented in the generated partial class.

Like this:

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

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

How do I handle dispose in this situation?


Solution

  • If you are going to modify Dispose implementation then copy it over to the code behind class from designer.cs. It is one of the few places in designer.cs that should be modified.

    The same is true for Windows Form class as well.