title: Creating a base class for Windows Services
body: <p>In our application, we have a number of Windows Services (more than 30) that must run behind the scenes to process data at given times throughout the day. I was attempting to create a BaseService class that I could inherit from that would log to our database when the service started or stopped as well as some other common functionality. However, I ran into a show stopper in trying to create BaseService as MustInherit as we have a number of MustOverride properties. The issue lies in:</p>
  
  <pre><code>&lt;MTAThread()&gt; Shared Sub Main()
  </code></pre>
  
  <p>Our code is all in VB (as you can probably tell). Given that it is a Shared method, I cannot have it be overridden (i.e. make it MustOverride). Without this method, the code will not compile, however it will not really work in the base class. The code in this method is:</p>
  
  <pre><code>Dim ServicesToRun() As System.ServiceProcess.ServiceBase
   ServicesToRun = New System.ServiceProcess.ServiceBase() {New BaseService}
   System.ServiceProcess.ServiceBase.Run(ServicesToRun)
  </code></pre>
  
  <p>The BaseService (the name of my base class) cannot be created because it is specified as MustInherit. And therein lies my problem. I cannot create this in the Base Class and cannot override it in the inheriting classes.</p>