0

I believe what I need is reflection, but after looking into it I'm not sure how I'm supposed to make it work.

I'm trying to run a second instance of the application that should tell the main instance to execute a procedure, and this code must run from the first instance. I've been able to identify if an instance is already running by using a mutex.

if (Mutex.WaitOne(TimeSpan.Zero, true) == false)
{
     //program already has an instance running
     //How do I call a method on the first (already running) instance
}

What I'd like it to do is execute a procedure from the first (already running) instance.

Servy
  • 202,030
  • 26
  • 332
  • 449
Michael Z.
  • 1,453
  • 1
  • 15
  • 21
  • @Servy So I would need to use WCF? I thought since it's the same executable and that I maintain the code that there would be a different way. – Michael Z. Mar 12 '18 at 20:59
  • 1
    This goes into IPC. But actually there is a class for this. It is somewhat hidden in the VB.Net specific DLL's, but it should still be useable.http://www.hanselman.com/blog/TheWeeklySourceCode31SingleInstanceWinFormsAndMicrosoftVisualBasicdll.aspx – Christopher Mar 12 '18 at 20:59
  • @MichaelZ. There are any number of ways to communicate between two processes. WCF is one of them. – Servy Mar 12 '18 at 21:01
  • @Servy Yeah, you're right. I suppose it could even be as easy as using a file. Thanks for the info. – Michael Z. Mar 12 '18 at 21:04
  • My app is a hotkey app and my current setup simply has the new instance send a hotkey that the first instance will pickup and handle. It's a hotkey that nobody would ever choose since it uses all four modifier keys. I think I'll just keep it the way it is. EDIT: it's not hotkeys persay, since I'm using a keyboard hook as opposed to the Win32 call `RegisterHotkey` – Michael Z. Mar 12 '18 at 21:09

0 Answers0