Update logica spegniemnto workerLoop da forced vs perdita PLC-OK esterna con riavvio adapter

This commit is contained in:
Samuele Locatelli
2026-01-08 10:42:38 +01:00
parent dcd9491539
commit eca8834b15
3 changed files with 48 additions and 27 deletions
+28 -8
View File
@@ -710,7 +710,7 @@ namespace IOB_WIN_FORM
/// Avvio l'adapter
/// </summary>
/// <param name="resetQueue">indica se sia richiesto di SVUOTARE le code delle info</param>
public void avviaAdapter(bool resetQueue)
public void AvviaAdapter(bool resetQueue)
{
displayTaskAndLog("Adapter starting", true);
// se NON sta girando...
@@ -1595,7 +1595,7 @@ namespace IOB_WIN_FORM
if (iobObj.adpTryRestart && (DateTime.Now > dtVeto))
{
lastStartTry = DateTime.Now;
avviaAdapter(chkForceDequeue.Checked);
AvviaAdapter(chkForceDequeue.Checked);
}
}
}
@@ -1759,7 +1759,7 @@ namespace IOB_WIN_FORM
{
displayTaskAndLog("Auto Starting...", true);
// avvio!
avviaAdapter(chkForceDequeue.Checked);
AvviaAdapter(chkForceDequeue.Checked);
displayTaskAndLog("Auto Started!", true);
}
}
@@ -1803,7 +1803,7 @@ namespace IOB_WIN_FORM
{
displayTaskAndLog("Auto Starting...", true);
// avvio!
avviaAdapter(chkForceDequeue.Checked);
AvviaAdapter(chkForceDequeue.Checked);
displayTaskAndLog("Auto Started!", true);
}
}
@@ -1971,7 +1971,7 @@ namespace IOB_WIN_FORM
loadIniFile(defConfFilePath);
displayTaskAndLog("RESTARTING: Ini File Reloaded", true);
// faccio start... CON RESET delle code
avviaAdapter(true);
AvviaAdapter(true);
displayTaskAndLog("RESTARTING: Adapter Started", true);
// resetto i data monitor...
dataMonitor_0 = "";
@@ -2059,7 +2059,8 @@ namespace IOB_WIN_FORM
/// <param name="e"></param>
private void start_Click(object sender, EventArgs e)
{
avviaAdapter(chkForceDequeue.Checked);
stopForced = false;
AvviaAdapter(chkForceDequeue.Checked);
// salvo che ho avviato adapter
lgInfo("Completato LOAD Adapter");
}
@@ -2069,8 +2070,9 @@ namespace IOB_WIN_FORM
/// </summary>
private void StartWorker()
{
// per prima cosa disattivo il disabled...
// rimozione isSuspended
_isSuspended = false;
// per prima cosa disattivo il disabled...
lock (_lock)
{
// 1. Controllo se è già in esecuzione
@@ -2093,11 +2095,14 @@ namespace IOB_WIN_FORM
/// <param name="e"></param>
private void stop_Click(object sender, EventArgs e)
{
stopForced = true;
fermaAdapter(false, chkForceDequeue.Checked, true);
// salvo che ho fermato adapter
lgInfo("UNLOAD Adapter");
}
private bool stopForced = false;
// Metodo per fermare tutto (es. nel Form_Closing o Dispose)
private async Task StopWorker()
{
@@ -2169,7 +2174,22 @@ namespace IOB_WIN_FORM
}
else
{
lgTrace("Task sospeso: NON esegue task specifici");
// se non fosse stop richiesto da utente...
if (!stopForced)
{
DateTime dtVeto = lastStartTry.AddMilliseconds(waitRecMSec / 2);
// verifica scadenza controllo SE fosse offline x eseguire test riconnessione...
if (iobObj.adpTryRestart && (DateTime.Now > dtVeto) && iobObj.adpRunning && !iobObj.connectionOk)
{
lgTrace($"WorkerLoopAsync sospeso: tentativo riavvio periodico");
lastStartTry = DateTime.Now;
iobObj.tryConnect();
}
else
{
lgTrace($"WorkerLoopAsync sospeso: NON esegue task specifici | _isSuspended: {_isSuspended}");
}
}
}
// Calcolo del delay dinamico da Timers.MsVHF
+19 -18
View File
@@ -3415,7 +3415,7 @@ namespace IOB_WIN_FORM.Iob
catch (Exception ex)
{
lgError($"Errore in SendStartPodl | {Environment.NewLine}{ex.Message}");
}
}
return answ;
}
@@ -3983,7 +3983,7 @@ namespace IOB_WIN_FORM.Iob
// PONTE SYNC/ASYNC: Ora sw.Stop() aspetterà la fine reale dell'operazione
Task.Run(async () =>
{
fatto= await TryCloseCurrODLAsync();
fatto = await TryCloseCurrODLAsync();
})
.GetAwaiter()
.GetResult();
@@ -4302,7 +4302,7 @@ namespace IOB_WIN_FORM.Iob
/// <summary>
/// Cerca di inviare su un altro thread i vari dati accumulati...
/// </summary>
protected async Task trySendValues()
protected async Task TrySendValuesAsync()
{
// init genObj display
newDisplayData currDispData = new newDisplayData();
@@ -4359,7 +4359,7 @@ namespace IOB_WIN_FORM.Iob
}
catch (Exception exc)
{
lgError($"Errore in fase trySendValues | currSendErrors: {currSendErrors}{Environment.NewLine}{exc}");
lgError($"Errore in fase TrySendValuesAsync | currSendErrors: {currSendErrors}{Environment.NewLine}{exc}");
currDispData.semOut = Semaforo.SR;
}
raiseRefresh(currDispData);
@@ -4377,7 +4377,7 @@ namespace IOB_WIN_FORM.Iob
// PONTE SYNC/ASYNC: Ora sw.Stop() aspetterà la fine reale dell'operazione
Task.Run(async () =>
{
fatto= await TrySetupPODLAsync(idxPODL);
fatto = await TrySetupPODLAsync(idxPODL);
})
.GetAwaiter()
.GetResult();
@@ -4773,7 +4773,10 @@ namespace IOB_WIN_FORM.Iob
string callResp = await callUrl(urlIobEnabled, i < 3); // true per i primi tentativi
if (callResp == "OK") return true;
}
catch { /* Retry silente */ }
catch (Exception exc)
{
lgError($"Eccez<ione in ExecuteIobCheckWithRetry{Environment.NewLine}{exc}");
}
}
return false;
}
@@ -4784,18 +4787,16 @@ namespace IOB_WIN_FORM.Iob
if (IobOnline != newStatus)
{
lgInfo(newStatus ? "IOB ONLINE for server MP/IO" : "IOB OFFLINE for server MP/IO");
}
IobOnline = newStatus;
if (newStatus)
{
lastIobOnline = DateTime.Now;
parentForm.commSrvActive = 2; // Stato Online
}
else
{
parentForm.commSrvActive = 1; // Stato Degradato/Offline
IobOnline = newStatus;
if (newStatus)
{
lastIobOnline = DateTime.Now;
parentForm.commSrvActive = 2; // Stato Online
}
else
{
parentForm.commSrvActive = 1; // Stato Degradato/Offline
}
}
// Imposto il veto per il prossimo controllo
+1 -1
View File
@@ -1355,7 +1355,7 @@ namespace IOB_WIN_FORM.Iob
// IN OGNI CASO a prima di tutto EFFETTUO GESTIONE INVII dati da code!!!
try
{
await trySendValues();
await TrySendValuesAsync();
}
catch (Exception exc)
{