Executing a method on the same app, other instance
Hello everybody,
I have an Application that allows one only instance. To accomplish this, I used this simple code on the Main() function.
Code:
Process[] runningProcesses = Process.GetProcessesByName(Application.ProductName.ToString());
if (runningProcesses.Length == 1){
Application.Run(new MainForm());
} else {
Application.Exit();
}
}
This is working indeed: when I run a second instance of my app, it silently kills itself. Well... almost too silently, that is.
Just before calling Application.Exit() I would like to restore a form (if needed) of the first, running instance. To do this, I'd have to call a method of the first instance from the second instance. How to do this? I found something on the internet about sendmessage and sendkeys but I got a bit puzzled.
If I could SendKeys a key to the first instance, that would be fine too: the method would be executed indirectly, triggered by a Context menuItem on my app trayicon.
I hope I made myswlf clear enough, thank you guys.