Program napisany jest z użyciem WindowsForms i ma się uruchamiać tylko raz.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace App
{
static class Program
{
[STAThread]
static void Main()
{
bool FirstRun;
try
{
using (Mutex mutex = new Mutex(true, "Example", out FirstRun))
{
if (FirstRun)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
mutex.ReleaseMutex();
}
}
}
catch (ApplicationException ee)
{
MessageBox.Show("Program jest już uruchomiony");
}
finally
{
Application.Exit();
}
}
}
}
A może jest lepsza metoda niż mutexy?
Czytałem coś o singletonach, jednak nie wiem czy pasują do tego przypadku...</quote>