title: C#: Thread-safe events
body: <p>Is the implementation below thread-safe? If not what am I missing? Should I have the <code>volatile</code> keywords somewhere? Or a lock somewhere in the <code>OnProcessingCompleted</code> method? If so, where?</p>
  
  <pre><code>public abstract class ProcessBase : IProcess
  {
      private readonly object completedEventLock = new object();
  
      private event EventHandler&lt;ProcessCompletedEventArgs&gt; ProcessCompleted;
  
      event EventHandler&lt;ProcessCompletedEventArgs&gt; IProcess.ProcessCompleted
      {
          add
          {
              lock (completedEventLock)
                  ProcessCompleted += value;
          }
          remove
          {
              lock (completedEventLock)
                  ProcessCompleted -= value;
          }
      }
  
      protected void OnProcessingCompleted(ProcessCompletedEventArgs e)
      {
          EventHandler&lt;ProcessCompletedEventArgs&gt; handler = ProcessCompleted;
          if (handler != null)
              handler(this, e);
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong><em>Note:</strong> The reason why I have private event and explicit interface stuff, is because it is an abstract base class. And the classes that inherit from it shouldn't do anything with that event directly. Added the class wrapper so that it is more clear =)</em></p>