title: Access windows forms controls from external DLLs in C#
body: <p>This is my first Topic here and I didn't find any similar Topics so I try to describe my problem as good as I can:</p>
  
  <p>I was ordered by my Company to create a modular C# program to assist our Software Developers with Background tasks. The Programm is composed of a Windows Forms application with a User Interface that calls external DLLs that do the actual work. All These DLLs are written by me aswell and follow certain rules to make them compatible to the Main App. That way I can easily add new funcions to the Programm just by putting the DLL into a predefined Folder. So to say Plug-and-Run</p>
  
  <p>The main program contains a ListBox that shows all available PlugIns and if one get's selected and the "start" button is clicked, the Main program calls the corresponding DLL and Invokes the method "program" that starts the DLLs actual function. Furthermore the Main contains a method "Output" that is supposed to write the result of every PlugIn into a Tab of my TabControl. That way the results of every PlugIn running in separate threads can be viewed independently. The Access to the tab already has a delegate to make it threadsafe. The Information is gathered by invoke from the PlugIn's own "returnOutput" method that simply Returns a List of strings containing the results to the Main.</p>
  
  <p>My Problem now is: How can i implement a Kind of a callback into my PlugIn DLLs so they can order the Main Program to gather the results at any time?</p>
  
  <p>My first idea was to simply add the result as return values to the "program" method itself but that would make the Information only available at the end of the program and some of the Tasks require a "live update" during runtime.</p>
  
  <p>My second idea was to use the delegate for the Control as Parameter and pass it to the PlugIn so the PlugIn DLL could Access the Control on it's own. This idea failed because the DLL doesn't "know" the Main program and can't Access it's Methods or the delegates instance so I am Always missing a reference.</p>
  
  <p>Is there a way to solve my problem? If necessary I can provide Code snippets but the program has already around 800 lines of Code and each PlugIn adds a few hundred more.. </p>
  
  <p>Thanks in advance for every answer and sorry for my non-native english :D</p>
  
  <p>Best Regards</p>
  
  <p>Gerrit "Raketenmaulwurf" M.</p>
  
  <p>Edit: I am using SharpDevelop 5.1</p>
  
  <p>Code Snippet for the DLL call:</p>
  
  <pre><code>PlugIn = PlugIns.SelectedItem.ToString();
  Assembly PlugInDLL = Assembly.LoadFile(@PlugInOrdner+"\\"+PlugIn+".dll");
  Object Objekt = PlugInDLL.CreateInstance("DLL.PlugIn");
  MethodInfo Info1 = Objekt.GetType().GetMethod("Programm");
  Info1.Invoke(Objekt, new Object[]{Projekt, TIAInstanz});
  </code></pre>
  
  <p>it basically Looks for a DLL file that has the same Name as the highlighted item in the ListBox </p>