Aggiunto Mutex x gestione single startup
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
<add key="windowCanMax" value="true" />
|
||||
<add key="trayClose" value="true" />
|
||||
<add key="startOnTray" value="true" />
|
||||
<!--Gestione istanze-->
|
||||
<add key="singleInstance" value="true" />
|
||||
</appSettings>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
|
||||
@@ -102,6 +102,8 @@ namespace LPA
|
||||
|
||||
#region init form + dispose
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Classe apertura
|
||||
/// </summary>
|
||||
@@ -111,6 +113,7 @@ namespace LPA
|
||||
myInit();
|
||||
checkShowTray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Medoti init specifici
|
||||
/// </summary>
|
||||
|
||||
+62
-12
@@ -1,22 +1,72 @@
|
||||
using System;
|
||||
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>
|
||||
/// Punto di ingresso principale dell'applicazione.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
static class Program
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MainForm());
|
||||
/// <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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user