73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using SteamWare.IO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace LPA
|
|
{
|
|
static class Program
|
|
{
|
|
/// <summary>
|
|
/// Mutex x evitare multiple instances
|
|
/// </summary>
|
|
static Mutex _m;
|
|
static bool IsSingleInstance()
|
|
{
|
|
try
|
|
{
|
|
// Try to open existing mutex.
|
|
_ = Mutex.OpenExisting("SteamwareLPA");
|
|
}
|
|
catch
|
|
{
|
|
// If exception occurred, there is no such mutex.
|
|
Program._m = new Mutex(true, "SteamwareLPA");
|
|
|
|
// Only one instance.
|
|
return true;
|
|
}
|
|
// More than one instance.
|
|
return false;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Punto di ingresso principale dell'applicazione.
|
|
/// </summary>
|
|
[STAThread]
|
|
static void Main()
|
|
{
|
|
bool enableStartup = true;
|
|
// se abilitato il controllo istanza (solo 1...)
|
|
if (memLayer.ML.CRB("singleInstance"))
|
|
{
|
|
utils.lgInfo("Single instance only: checking!");
|
|
if (!Program.IsSingleInstance())
|
|
{
|
|
utils.lgInfo("More than one instance found: exiting");
|
|
enableStartup = false;
|
|
}
|
|
else
|
|
{
|
|
// Continue with program.
|
|
Console.WriteLine("OK! only One instance running");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
utils.lgInfo("Multiple instance allowed: check not requested");
|
|
}
|
|
// se abilitato procedo
|
|
if (enableStartup)
|
|
{
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Application.Run(new MainForm());
|
|
}
|
|
}
|
|
}
|
|
}
|