exe nur einmal starten
-
hallo,
ich möchte verhindern, dass ein programm öfter als 1x gestartet wird. da habe ich foldendermaßen gelöst:
static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // generate mutex to allow only one instance of keycounter Mutex mutex = new Mutex(false, Application.ProductName + "ad90g7a9d7"); if (mutex.WaitOne(0, false)) Application.Run(new FormMain()); else MessageBox.Show("You can start only one instance of " + Application.ProductName + "!", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
Wenn ich nun das ganze unter VS2005 Express im Debugmodus kompiliere dann funktioniert es. Im Releasemodus greift's nicht. Woran kann das liegen?
mfg unclejamal
-
Hi
Bei mir läufts (Debug und Release).
Simon
-
[cs]
bool pobjIOwnMutex = false;
System.Threading.Mutex pobjMutex = new System.Threading.Mutex(true, "mutexname", out pobjIOwnMutex);if (pobjIOwnMutex)
{
pobjMutex.ReleaseMutex();
}
else
{
// Programm läuft schon
}
-
ok, danke
werde ich dann gleich ausprobieren...