Im currently trying to create a "watchdog" in c# which checks if a mutex is in use, if it is everything is good, if not --> start the application.
Works fine for the first time, but as soon as the main application stops / ends, it wont recognize that. It still thinks that the mutex is in use and also seems to lock it to the watchdog process?
string mutexdog = "dog";
try
{
Mutex.OpenExisting(mutexdog);
System.Environment.Exit(0);
}
catch
{
Program._m = new Mutex(true, mutexdog);
}
while(true)
{
string mutexmain = "main";
try
{
Mutex.OpenExisting(mutexmain);
Console.WriteLine("Main is running");
}
catch
{
Console.WriteLine("Main is not running, starting!");
Process p = new Process();
p.StartInfo.FileName = "main.exe";
p.Start();
Thread.Sleep(1500);
}
Thread.Sleep(500);
}
Is there any way to check if a mutex is being used without locking it up? I would prefer to do it over a mutex due to multiple reason and other issues i had previously by checking for a process name...