I've put together an application that I plan on writing plugins for. In order to keep everything separate and make updating easy, I figured writing individual class libraries would be the best solution. The problem I'm running into is that my dll can't communicate with it's parent. Is this only one-way communication?
I dynamically load the dll at runtime and can tell it to do what I want it to do without any problems. The problem I encounter is after it's finished doing its work, I can't get it to signal the parent that it's finished. I don't want the parent to hang and wait for it, so I open a new thread in the dll to do the "work". I tried something as simple as passing a self reference to the dll when it's opened, but I get an access violation when I try to access something on the parent from the DLL.
All of my searches come up mentioning WCF and named pipes. I feel like it should be a simpler solution than this, like the self reference. Is WCF the way to go for this? Any other/better solutions?
ModuleHandler.cs:
using System;
using System.IO;
using System.Reflection;
namespace Collector
{
class ModuleHandler
{
public ModuleHandler()
{
LoadStaticModules();
}
private void LoadStaticModules()
{
Assembly assembly = Assembly.Load("Module_WaitForIt");
Type[] types = assembly.GetTypes();
dynamic module = Activator.CreateInstance(types[0]);
module.StartSleeping();
}
public void TestMethod()
{
Console.WriteLine("TestMethod()");
}
}
}
Module_WaitForIt:
using System.Threading;
namespace Module_WaitForIt
{
public class WaitModule
{
public void StartSleeping()
{
System.Console.WriteLine("Sleeping");
Thread t = new Thread(() => SleepyThread());
}
public void SleepyThread()
{
Thread.Sleep(10000);
}
}
}
In this example, I want Module_WaitForIt.SleepyThread() to call ModuleHandler.TestMethod() after it sleeps for 10 seconds.