View Full Version : Max numero stesso processo in esecuzione
Ciao a tutti, come posso fare a dare un limite al numero di un processo in windows server? per esempio: il "mioprogramma.exe" deve avere il limiti di massimo 5 processi (tra tutti gli user windows) contemporaneamente in esecuzione.
grazie per l'aiuto
wingman87
12-10-2020, 11:30
Se il programma lo hai scritto tu, puoi usare un semaforo machine-wide.
Per .NET:
https://docs.microsoft.com/en-us/dotnet/api/system.threading.semaphore.-ctor?view=netframework-4.5.2#System_Threading_Semaphore__ctor_System_Int32_System_Int32_System_String_
Ad esempio in C#:
var semaphoreObject = new Semaphore(5, 5, "Global\\MioProgramma");
bool ownSemaphore = false;
try
{
ownSemaphore = semaphoreObject.WaitOne(); //Restituisce sempre true ma se va in errore ownSemaphore resterà false
// fai quello che devi fare
}
catch (Exception ex)
{
}
finally
{
if (ownSemaphore)
semaphoreObject.Release();
}
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.