0

I am after ideas on how to call back to a main exe from a dynamically loaded dll ? (NB: this dll will be unloaded at some point after the callback)

Context C#

I am prototyping a service which during development then later on, can update its core. I have a stub main which will do the service calls into the “main dll”. I want to be able to call back into the main exe to tell it to reload the core dll after a fresh copy of the latest dll is done. I have the load – unload working. However I can’t get a callback or update of a passed IntPtr to work and other similar ideas to work. E.g.

    loader.ExecuteStaticMethod(cMain_DLL, "Class1", "My_CallBack", new object[] {out _Count }); 

wont compile

I have used a slightly modified http://www.c-sharpcorner.com/uploadfile/girish.nehte/how-to-unload-an-assembly-loaded-dynamically-using-reflection/ to load and unload the dll, as well as call functions in the dll.

        Type[] types = parameters.Select(o=>o.GetType()).ToArray();

        MethodInfo MyMethod = MyType.GetMethod(methodName, types); <= can retun null for some objects
        MyMethod.Invoke(inst, BindingFlags.InvokeMethod, null, parameters, null);
rene
  • 41,474
  • 78
  • 114
  • 152
Greg B Roberts
  • 173
  • 4
  • 14
  • http://stackoverflow.com/questions/2438065/c-sharp-reflection-how-can-i-invoke-a-method-with-an-out-parameter – apocalypse Dec 20 '16 at 08:58

1 Answers1

1

If you need only reload event, check EventWaitHandle. Your stub can WaitOne() on that handle and action accordingly once service calls Set().

Alex Seleznyov
  • 905
  • 6
  • 18
  • Could you please give me a url or example? I am not familiar enough with what you are referring to to know which part is in the main.exe and which is in the loaded dll. Thanks – Greg B Roberts Dec 20 '16 at 09:51
  • Stub part: `var reloadEvent = new EventWaitHandle(false, EventResetMode.ManualReset, "MyUniqueName'); ... //load your library ... reloadEvent.WaitOne(); ... //reload here` Library part: `var reloadEvent = new EventWaitHandle(false, EventResetMode.ManualReset, "MyUniqueName'); // trigger reload reloadEvent.Set(); ` – Alex Seleznyov Dec 20 '16 at 09:58