title: WCF Service Shutdown
body: <p>I have a single instance WCF service class that is self hosted using a Windows service. I set up the service host in the OnStart event and I close the service in the OnStop event.</p>
  
  <p>In the service class I implement a destructor and I have some clean-up code in there. Essentially the clean-up code serialises some internal objects to disk for next time and should produce two files.</p>
  
  <p>What I am seeing is sometimes two files, sometimes one, sometimes empty files where there should be data in them. It seems like the destructor isn't getting time to complete the serialisation of the objects before the entire service process is ended.</p>
  
  <p>Is this the typical way to do housekeeping just before a service shuts down, or is there a better way?</p>