I'm having a seriously problem with my little application; basically it's very easy to understand:
My software, when opened, do it's things.
I want to focus to opening another instance (And I mean opening again the .exe) ,check if it's already opened. If not simply start the application but if it's already running (AKA second or more instance) "simply" pass input argument (the args string array)to the first instance, that will processate it adeguately.
Here's my program.cs
static class Program
{
static Mutex mutex = new Mutex(true, "{blabla}");
[STAThread]
static void Main(String[] args)
{
if (mutex.WaitOne(TimeSpan.Zero, true))
{
//First Instance!
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
CALL A MY STATIC METHOD, DO SOME THINGS
Application.Run(new Form1());
}
finally
{
mutex.ReleaseMutex();
}
}
else
{
//Not-so-first instance!
CALL A STATIC METHOD,
DO OTHER THINGS LIKE COMUNICATE WITH FIRST INSTANCE
SIMPLY CLOSE.
}
}
}
This will only recognize (with mutex) if it's already opened but (off course) it can't communicate anything to the main instance.
I've tried lot of things but I can't get it work.
I've tried this but I seriously don't understand (after a lot of time wasted) how to put my "first time" code and the "already running" code.
Tried also MSMQ but I can't make it work.
Can someone please help me? It's a basic software that do a very basic things but I've spent day to make it work like I want!
static
isn't going to do it. The fact that you're running multiple copies of the same executable does not make the problem simpler than communicating between different apps. – Meneses