title: Raise an event from a custom class
body: <p>I have a Windows Service project designed to monitor an email account and make entries into a SQL Server database when certain emails arrive. This is a rewrite of a similar winforms program that works just fine, except that it requires that the computer be logged into an account and the program started manually, which I can avoid by using it as a service.</p>
  
  <p>In the service I maintain a list of logged messages - basically just a string and a timestamp indicating that something has happened. (That list is shared out over a WCF service but I think that's immaterial, at least at the moment.) In my custom class I declare a public event, and elsewhere I raise that event. For some reason, though, the <code>RaiseEvent</code> isn't being run in the service. For example:</p>
  
  <pre><code>Public Class TheService
      Private WithEvents _pc As ProcessorClass
  
      Public Sub OnStart(ByVal args() As String)
          _pc = New ProcessorClass
      End Sub
      ...
      Private Sub _pc_HandleEvent(LogMessage As String) Handles _pc.CustomEvent
          'do something with the LogMessage
      End Sub
  End Class
  
  Public Class ProcessorClass
      Public Event CustomEvent(ByVal LogMessage As String)
      ...
      Public Sub Process()
          'Do stuff
          RaiseEvent CustomEvent("Event raised")
      End Sub
  End Class
  </code></pre>
  
  <p>The problem in this case is that <code>_pc_HandleEvent</code> isn't ever being called. If I duplicate this setup in a regular winform program, everything works like it should. What am I doing wrong? How do I get a service to handle events raised from other classes?</p>