title: C# multiple sources, different threads, one event handler
body: <p>I need somebody with high skills in threading and event raising.</p>
  
  <p>I have an abstract class <code>A</code> and two concrete classes <code>C1</code>, <code>C2</code> (e.g plugins). </p>
  
  <p>Since I need them to communicate between each other, like "plugin-application" "plugin-plugin" communication, I have a method <code>ExecuteCommand</code> in the abstract class which should accomplish this. This function raises an <code>event</code> to the application in order to process a certain command and return the result (e.g if one plugin needs data from the app it calls <code>ExecuteCommand</code> from the base and waits for the result which comes with the event handler processed on the application).</p>
  
  <pre><code>protected object ExecuteCommand(SvcCmdType cmdType, params object[] inputParams)
  {
    // this code has been simplified
    SvcCommandEventArgs eventArgs = new SvcCommandEventArgs(cmdType, inputParams);
  
    // generate processing command event (it requires to fill in the result)
    OnProcessingAppCommand(this, eventArgs);
  
    return eventArgs.OutputParamsList; 
  }
  </code></pre>
  
  <p>The <strong><em>problem</em></strong> is: </p>
  
  <p>If each one of <code>C1</code> and <code>C2</code> have different threads behind and call simultaneously <code>ExecuteCommand</code> from inside their own threads then for sure my design will be broken and the result returned will be unexpected.</p>
  
  <p>What is the best design for this scenario? I was thinking to use inside <code>ExecuteCommand</code> asynchronous calls like using <code>AsyncOperation</code>... but is it the right way?</p>
  
  <p><em>edited:</em>
  I guess I am looking for: is the synchronous or asynchronous way better for my scenario? Or, shall I have the app event handler processed inside a plugin's thread or synchronized somewhere in my main thread?</p>
  
  <p>I would really appreciate some good explanations for your recommendations</p>
  
  <p>Thank you.</p>