title: C# Communication between plugin and host application
body: <p>I am writing plugin based application.</p>
  
  <p>Host application:</p>
  
  <pre><code>namespace CSK
  {
  /// &lt;summary&gt;
  /// Interaction logic for MainWindow.xaml
  /// &lt;/summary&gt;
  public partial class MainWindow : Window
  {
  
      public MainWindow()
      {                  
          InitializeComponent();
          LoadPlugins();
  
      }
  
      public void LoadPlugins()
      {
          DirectoryInfo di = new DirectoryInfo("./Plugins");
  
          foreach (FileInfo fi in di.GetFiles("*_Plugin.dll"))
          {
              Assembly pluginAssembly = Assembly.LoadFrom(fi.FullName);
  
              foreach (Type pluginType in pluginAssembly.GetExportedTypes())
              {
  
                  if (pluginType.GetInterface(typeof(MainInterface.PluginHostInterface).Name) != null)
                  {
                      MainInterface.PluginHostInterface TypeLoadedFromPlugin = (MainInterface.PluginHostInterface)Activator.CreateInstance(pluginType);
                      MainInterface.IMother mother = new ApiMethods(this);
                      TypeLoadedFromPlugin.Initialize(mother);
                  }
  
              }
          }
      }
  }
  </code></pre>
  
  <p>Interface:</p>
  
  <pre><code>namespace MainInterface
  {
  public interface PluginHostInterface
  {
      void Initialize(IMother mother);
  }
  
  public interface IMother
  {
      MenuItem addMenuItem(String header, String name);
      MenuItem addSubMenuItem(MenuItem menu, String header, String name);
      Boolean receiveMessage(String message, String from);
      Boolean addContact(String name, String status, String proto, String avatar = "av");
  }
  }
  </code></pre>
  
  <p>Test plugin:</p>
  
  <pre><code>namespace Plugin_Test
  {
  public class MainClass : MainInterface.PluginHostInterface
  {
      private MainInterface.IMother CSK;
  
      public void Initialize(MainInterface.IMother mainAppHandler)
      {
          CSK = mainAppHandler;
  
      }
  
  }
  }
  </code></pre>
  
  <p>And now, i want to execute some methods in Plugin Test from my host application. Of course, there will be many plugins, and not every of them will contain specified methods. I was trying to use events but with no success. Any idea how to do it?</p>