diff --git a/IOB-WIN-FORM/AdapterForm.cs b/IOB-WIN-FORM/AdapterForm.cs index 90a8262d..d9e4acdd 100644 --- a/IOB-WIN-FORM/AdapterForm.cs +++ b/IOB-WIN-FORM/AdapterForm.cs @@ -710,7 +710,7 @@ namespace IOB_WIN_FORM /// Avvio l'adapter /// /// indica se sia richiesto di SVUOTARE le code delle info - 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 /// 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 /// 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 /// 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 diff --git a/IOB-WIN-FORM/Iob/Generic.Protected.cs b/IOB-WIN-FORM/Iob/Generic.Protected.cs index 050e5694..79aac4b6 100644 --- a/IOB-WIN-FORM/Iob/Generic.Protected.cs +++ b/IOB-WIN-FORM/Iob/Generic.Protected.cs @@ -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 /// /// Cerca di inviare su un altro thread i vari dati accumulati... /// - 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