From f1f8cbd60b52b4c814ede42992ab70914a941773 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 25 May 2026 12:29:36 +0200 Subject: [PATCH] Update condizione display update UI x ridurre CPU su AdapterForm --- IOB-WIN-FANUC/DATA/CONF/MAIN.ini | 3 +- IOB-WIN-FANUC/Iob/Fanuc.cs | 6 +- IOB-WIN-FORM/AdapterForm.Designer.cs | 54 +++++------ IOB-WIN-FORM/AdapterForm.cs | 139 +++++++++++++++++++++++---- IOB-WIN-FORM/AdapterForm.resx | 3 - IOB-WIN-FORM/Iob/Generic.cs | 11 --- IOB-WIN-FORM/Iob/Simula.cs | 50 ++++------ IOB-WIN-FTP/DATA/CONF/MAIN.ini | 1 + IOB-WIN-MTC/DATA/CONF/MAIN.ini | 1 + IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini | 1 + IOB-WIN-PING/DATA/CONF/MAIN.ini | 1 - IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini | 3 +- IOB-WIN-WPS/DATA/CONF/MAIN.ini | 3 +- 13 files changed, 178 insertions(+), 98 deletions(-) diff --git a/IOB-WIN-FANUC/DATA/CONF/MAIN.ini b/IOB-WIN-FANUC/DATA/CONF/MAIN.ini index f621315d..1d21585c 100644 --- a/IOB-WIN-FANUC/DATA/CONF/MAIN.ini +++ b/IOB-WIN-FANUC/DATA/CONF/MAIN.ini @@ -33,4 +33,5 @@ CLI_INST=SteamWareSim ;STARTLIST=3001 STARTLIST=SIMUL_01 -MAXCNC=10 + + diff --git a/IOB-WIN-FANUC/Iob/Fanuc.cs b/IOB-WIN-FANUC/Iob/Fanuc.cs index 88a488dd..a0ebcb06 100644 --- a/IOB-WIN-FANUC/Iob/Fanuc.cs +++ b/IOB-WIN-FANUC/Iob/Fanuc.cs @@ -89,7 +89,7 @@ namespace IOB_WIN_FANUC.Iob FANUC_ref = (FANUC)Runtime.NC; tryDisconnect(); - Thread.Sleep(500); + Thread.Sleep(200); lgInfo("FANUC: tryConnect"); tryConnect(); @@ -1570,7 +1570,7 @@ namespace IOB_WIN_FANUC.Iob FANUC_ref.Disconnect(ref szStatusConnection); lgInfo($"FANUC_ref preliminary DISCONNECT | connStatus: {FANUC_ref.Connected}| szStatusConnection: {szStatusConnection}"); // aspetto - Thread.Sleep(500); + Thread.Sleep(200); } FANUC_ref.Connect(ref szStatusConnection); parentForm.commPlcActive = false; @@ -1627,7 +1627,7 @@ namespace IOB_WIN_FANUC.Iob try { FANUC_ref.Disconnect(ref szStatusConnection); - Thread.Sleep(500); + Thread.Sleep(200); connectionOk = false; // resetto timing! TimingData.resetData(); diff --git a/IOB-WIN-FORM/AdapterForm.Designer.cs b/IOB-WIN-FORM/AdapterForm.Designer.cs index a676c61c..3461c013 100644 --- a/IOB-WIN-FORM/AdapterForm.Designer.cs +++ b/IOB-WIN-FORM/AdapterForm.Designer.cs @@ -33,7 +33,6 @@ this.lblPzCountIob = new System.Windows.Forms.Label(); this.lblPzCountMac = new System.Windows.Forms.Label(); this.chkForceDequeue = new System.Windows.Forms.CheckBox(); - this.displTimer = new System.Windows.Forms.Timer(this.components); this.tabMes = new System.Windows.Forms.TabPage(); this.btnForceAutoOdl = new System.Windows.Forms.Button(); this.panel1 = new System.Windows.Forms.Panel(); @@ -150,7 +149,7 @@ // // tableLayoutPanel1 // - this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.ColumnCount = 10; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 24F)); @@ -183,8 +182,8 @@ // // restart // - this.restart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.restart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.restart.BackColor = System.Drawing.Color.Red; this.restart.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -199,8 +198,8 @@ // // stop // - this.stop.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.stop.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.stop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.stop.ForeColor = System.Drawing.SystemColors.ControlText; @@ -226,8 +225,8 @@ // // start // - this.start.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.start.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.start.BackColor = System.Drawing.SystemColors.Control; this.start.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -242,8 +241,8 @@ // // bIN // - this.bIN.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.bIN.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.bIN.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.bIN.Location = new System.Drawing.Point(2, 2); @@ -257,8 +256,8 @@ // // bOUT // - this.bOUT.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.bOUT.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.bOUT.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.bOUT.Location = new System.Drawing.Point(879, 2); @@ -285,8 +284,8 @@ // // lblPzCountIob // - this.lblPzCountIob.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.lblPzCountIob.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lblPzCountIob.AutoSize = true; this.lblPzCountIob.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -323,10 +322,6 @@ this.chkForceDequeue.Text = "F"; this.chkForceDequeue.UseVisualStyleBackColor = true; // - // displTimer - // - this.displTimer.Tick += new System.EventHandler(this.displTimer_Tick); - // // tabMes // this.tabMes.BackColor = System.Drawing.Color.Transparent; @@ -607,8 +602,8 @@ // // panel2 // - this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.panel2.AutoScroll = true; this.panel2.Controls.Add(this.lblTaskLog); @@ -875,8 +870,8 @@ // // flowLayoutPanel1 // - this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.flowLayoutPanel1.Controls.Add(this.lblLogfile); this.flowLayoutPanel1.Location = new System.Drawing.Point(6, 22); @@ -910,8 +905,8 @@ // // tableLayoutPanel2 // - this.tableLayoutPanel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.tableLayoutPanel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel2.BackColor = System.Drawing.Color.Black; this.tableLayoutPanel2.ColumnCount = 4; @@ -974,7 +969,7 @@ // // lblRawData // - this.lblRawData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.lblRawData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lblRawData.AutoSize = true; this.lblRawData.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -1011,7 +1006,7 @@ // // lblOutMessage3 // - this.lblOutMessage3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.lblOutMessage3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lblOutMessage3.AutoSize = true; this.lblOutMessage3.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -1025,7 +1020,7 @@ // // lblOutMessage2 // - this.lblOutMessage2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.lblOutMessage2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lblOutMessage2.AutoSize = true; this.lblOutMessage2.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -1038,8 +1033,8 @@ // // tabData // - this.tabData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.tabData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tabData.Controls.Add(this.tabRealtime); this.tabData.Controls.Add(this.tabLog); @@ -1110,7 +1105,6 @@ private System.Windows.Forms.Button start; private System.Windows.Forms.TextBox nLines; private System.Windows.Forms.Button bIN; - private System.Windows.Forms.Timer displTimer; private System.Windows.Forms.Button restart; private System.Windows.Forms.CheckBox chkForceDequeue; private System.Windows.Forms.Button bOUT; diff --git a/IOB-WIN-FORM/AdapterForm.cs b/IOB-WIN-FORM/AdapterForm.cs index a8a89858..336486cc 100644 --- a/IOB-WIN-FORM/AdapterForm.cs +++ b/IOB-WIN-FORM/AdapterForm.cs @@ -1342,6 +1342,10 @@ namespace IOB_WIN_FORM /// Cancellation tocken x processi verso server /// private CancellationTokenSource _ctsServer; + /// + /// Cancellation tocken x processi verso Redis + /// + private CancellationTokenSource _ctsRedis; /// /// Ritardo per errori (extra nei cicli) @@ -1354,6 +1358,7 @@ namespace IOB_WIN_FORM private FormWindowState _lastState = FormWindowState.Minimized; private Thread _machineThread; + private Task _redisTask; private Task _workerTask; /// @@ -1444,11 +1449,6 @@ namespace IOB_WIN_FORM gather.Enabled = true; displayTaskAndLog($"Main UI timer set: {gather.Interval}ms", true); - // Start timer periodico interfaccia - displTimer.Interval = utils.CRI("timerIntMs"); - displTimer.Enabled = true; - displayTaskAndLog("UI Program Running", true); - // check oggetto not null if (iobObj != null) { @@ -1691,18 +1691,12 @@ namespace IOB_WIN_FORM private void CloseTimers() { - displTimer?.Stop(); - displTimer?.Dispose(); gather?.Stop(); gather?.Dispose(); _isSuspended = true; _ = StopWorker(); } - private void displTimer_Tick(object sender, EventArgs e) - { - } - /// /// Metodo principale esecuzione task in thread background (no interferenza con UI) x processi IO bound /// @@ -2140,6 +2134,9 @@ namespace IOB_WIN_FORM private void refreshFormData() { + // verifica se mostrare update + if (!ShouldUpdateUI()) return; + // aggiorno visualizzazioni varie in form... alQueueLen = iobObj.QHelp.QueueAlarm.Count; evQueueLen = iobObj.QHelp.QueueIN.Count; @@ -2150,6 +2147,7 @@ namespace IOB_WIN_FORM // aggiorno labels counters... counterIob = $"pz MES {iobObj.contapezziIOB}"; counterMac = $"pz PLC {iobObj.contapezziPLC}"; +#if false Dictionary setPar = new Dictionary(); setPar.Add("IP", iobObj.IOBConfFull.Device.Connect.IpAddr); setPar.Add("PORT", iobObj.IOBConfFull.Device.Connect.Port); @@ -2193,7 +2191,8 @@ namespace IOB_WIN_FORM // salvo su redis e in obj corrente iobObj.redisMan.servStatus = currSrvStatus; lastSrvStatus = currSrvStatus; - } + } +#endif } /// @@ -2338,10 +2337,6 @@ namespace IOB_WIN_FORM /// private void StartWorker() { - //// FixMe ToDo !!! togliere o fare alternativa pooled - //if (iobObj.IOBConfFull.General.MachWLoopSingleThread || true) - //{ - //} lock (_threadLock) { // rimozione isSuspended @@ -2374,7 +2369,22 @@ namespace IOB_WIN_FORM _machineThread.Start(); lgInfo("--- WORKER MACHINE AVVIATO ---"); - // avvio altro thread comunque... + // avvio altro thread di verifica status IOB verso REDIS... + // 1. Controllo se è già in esecuzione + if (_redisTask != null && !_redisTask.IsCompleted) + { + lgTrace("Worker Redis già in esecuzione. Richiesta ignorata."); + } + else + { + // avvio componente multithreaded x update + _ctsRedis = new CancellationTokenSource(); + _redisTask = Task.Run(() => RedisWorkerLoopAsync(_ctsRedis.Token)); + lgInfo("--- WORKER REDIS AVVIATO ---"); + } + + + // avvio altro thread di comunicazione server... // 1. Controllo se è già in esecuzione if (_workerTask != null && !_workerTask.IsCompleted) { @@ -2454,6 +2464,101 @@ namespace IOB_WIN_FORM checkAssignSize(); } + /// + /// Metodo x gestione I/O Redis (status IOB) + /// + /// + /// + private async Task RedisWorkerLoopAsync(CancellationToken token) + { + while (!token.IsCancellationRequested) + { + try + { + if (iobObj != null) + { + // 1. Estrazione dati dalle code (operazione logica) + long alQueueLen = iobObj.QHelp.QueueAlarm.Count; + long evQueueLen = iobObj.QHelp.QueueIN.Count; + long flQueueLen = iobObj.QHelp.QueueFLog.Count; + long msQueueLen = iobObj.QHelp.QueueMessages.Count; + long rtrQueueLen = iobObj.QHelp.QueueRawTransf.Count; + long ulQueueLen = iobObj.QHelp.QueueULog.Count; + + var setPar = new Dictionary + { + { "IP", iobObj.IOBConfFull.Device.Connect.IpAddr }, + { "PORT", iobObj.IOBConfFull.Device.Connect.Port } + }; + + IobWinStatus currIobStatus = new IobWinStatus() + { + CodIob = iobObj.IOBConfFull.General.FilenameIOB, + IobType = $"{iobObj.IOBConfFull.General.IobType}", + queueAlLen = alQueueLen, + queueEvLen = evQueueLen, + queueFlLen = flQueueLen, + queueMsLen = msQueueLen, + queueRawTransfLen = rtrQueueLen, + queueUlLen = ulQueueLen, + counterIOB = iobObj.contapezziIOB, + counterMAC = iobObj.contapezziPLC, + lastUpdate = lastIobStatus.lastUpdate > iobObj.DtHelp.lastWatchDog ? lastIobStatus.lastUpdate : iobObj.DtHelp.lastWatchDog, + online = utils.IOB_Online, + lastDataIn = iobObj.DtHelp.lastReadPLC, + lastDataOut = iobObj.DtHelp.lastIobOnline, + setupParams = setPar, + freeNotes = $"{iobObj.IOBConfFull.General.FilenameIOB} | DT ultimo avvio: {iobObj.DtHelp.AvvioAdp}" + }; + + // 2. Logica di salvataggio su REDIS (Rete -> Thread di background!) + if (!currIobStatus.Equals(lastIobStatus)) + { + currIobStatus.lastUpdate = DateTime.Now; + iobObj.redisMan.iobStatus = currIobStatus; + lastIobStatus = currIobStatus; + } + + if (lastSrvStatus.online != utils.MPIO_Online) + { + ServerMpStatus currSrvStatus = iobObj.redisMan.servStatus; + currSrvStatus.online = utils.MPIO_Online; + currSrvStatus.lastUpdate = DateTime.Now; + iobObj.redisMan.servStatus = currSrvStatus; + lastSrvStatus = currSrvStatus; + } + + // 3. Prepariamo i dati per la UI e li salviamo in modo thread-safe + lock (_statusLock) + { + _latestSnapshotForUI = currIobStatus; + _cachedCounterIob = $"pz MES {iobObj.contapezziIOB}"; + _cachedCounterMac = $"pz PLC {iobObj.contapezziPLC}"; + } + } + } + catch (Exception exc) + { + lgError($"Eccezione nel background gather: {exc}"); + } + + // Frequenza di aggiornamento Redis/Code (es. ogni 1 secondo) + // Rilascia la CPU senza fare context switch distruttivi + await Task.Delay(1000, token); + } + } + + // Oggetto per il lock thread-safe + private readonly object _statusLock = new object(); + + // Questa variabile conterrà l'ultimo stato valido calcolato in background + private IobWinStatus _latestSnapshotForUI; + + // Stringhe pronte per la UI calcolate in background per evitare manipolazioni di stringhe sul thread UI + private string _cachedCounterIob = ""; + private string _cachedCounterMac = ""; + private string _cachedNote = ""; + /// /// Loop di gestione worker /// diff --git a/IOB-WIN-FORM/AdapterForm.resx b/IOB-WIN-FORM/AdapterForm.resx index 05d5a47f..ea95e6b5 100644 --- a/IOB-WIN-FORM/AdapterForm.resx +++ b/IOB-WIN-FORM/AdapterForm.resx @@ -123,9 +123,6 @@ 118, 17 - - 645, 17 - ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- diff --git a/IOB-WIN-FORM/Iob/Generic.cs b/IOB-WIN-FORM/Iob/Generic.cs index aedaf648..1f3db8c2 100644 --- a/IOB-WIN-FORM/Iob/Generic.cs +++ b/IOB-WIN-FORM/Iob/Generic.cs @@ -757,33 +757,23 @@ namespace IOB_WIN_FORM.Iob else if (ciclo == gatherCycle.HF) { processWhatchDog(); - //Thread.Sleep(5); processAllMemory(); } else if (ciclo == gatherCycle.MF) { processMode(); - //Thread.Sleep(5); ExecServerRequests(); - //Thread.Sleep(5); processCustomTaskMF(); - //Thread.Sleep(5); processOverride(); - //Thread.Sleep(5); processContapezzi(); - //Thread.Sleep(5); processCncAlarms(); - //Thread.Sleep(5); processDynData(); - //Thread.Sleep(5); processMem2Write(); } else if (ciclo == gatherCycle.LF) { processCustomTaskLF(); - //Thread.Sleep(5); processOtherCounters().GetAwaiter().GetResult(); ; - //Thread.Sleep(5); processProgram(); } else if (ciclo == gatherCycle.VLF) @@ -793,7 +783,6 @@ namespace IOB_WIN_FORM.Iob processSysInfo(); if (enableSlowData) { - //Thread.Sleep(5); processSlowDataRead(); } } diff --git a/IOB-WIN-FORM/Iob/Simula.cs b/IOB-WIN-FORM/Iob/Simula.cs index 5a7f0fc9..5bc98e82 100644 --- a/IOB-WIN-FORM/Iob/Simula.cs +++ b/IOB-WIN-FORM/Iob/Simula.cs @@ -958,41 +958,31 @@ namespace IOB_WIN_FORM.Iob /// protected override void ProcessDataSync() { - try + _ = Task.Run(async () => { - // Eseguiamo il lavoro in un Task per non bloccare il thread chiamante, - // ma evitiamo il .GetAwaiter().GetResult() che causerebbe un blocco sincrono pesante. - // In un ambiente WinForms, questo permette al thread di polling di non restare in attesa attiva. - _ = Task.Run(async () => + try { - try - { - // Esecuzione dei task sincroni esistenti - iobWriteLocalCSV(); - iobSendFTP(""); - IobGetDataFromServer(); + // Esecuzione dei task sincroni esistenti + iobWriteLocalCSV(); + iobSendFTP(""); + IobGetDataFromServer(); - // Avvio dei task asincroni in parallelo - var taskOdl = ProcessAutoOdlAsync(); - var taskImport = ProcessFileImportAsync(); - var taskRecipe = ProcessRecipeFileRetAsync(); + // Avvio dei task asincroni in parallelo + var taskOdl = ProcessAutoOdlAsync(); + var taskImport = ProcessFileImportAsync(); + var taskRecipe = ProcessRecipeFileRetAsync(); - // Attendiamo il completamento dei task asincroni senza bloccare thread di sistema - await Task.WhenAll(taskOdl, taskImport, taskRecipe); + // Attendiamo il completamento dei task asincroni senza bloccare thread di sistema + await Task.WhenAll(taskOdl, taskImport, taskRecipe); - // Task finale sincrono - ProcessAutoDossier(); - } - catch (Exception ex) - { - lgError($"Errore interno Task.Run in ProcessDataSync: {ex.Message}"); - } - }); - } - catch (Exception exc) - { - lgError($"Eccezione in ProcessDataSync (wrapper): {exc.Message}"); - } + // Task finale sincrono + ProcessAutoDossier(); + } + catch (Exception ex) + { + lgError($"Errore asincrono Task.Run in ProcessDataSync: {ex.Message}"); + } + }); } /// diff --git a/IOB-WIN-FTP/DATA/CONF/MAIN.ini b/IOB-WIN-FTP/DATA/CONF/MAIN.ini index 2cb4f81c..d10acd09 100644 --- a/IOB-WIN-FTP/DATA/CONF/MAIN.ini +++ b/IOB-WIN-FTP/DATA/CONF/MAIN.ini @@ -21,3 +21,4 @@ STARTLIST=FTP_SONATEST MAXCNC=10 + diff --git a/IOB-WIN-MTC/DATA/CONF/MAIN.ini b/IOB-WIN-MTC/DATA/CONF/MAIN.ini index 4b123815..b8e74cd4 100644 --- a/IOB-WIN-MTC/DATA/CONF/MAIN.ini +++ b/IOB-WIN-MTC/DATA/CONF/MAIN.ini @@ -27,3 +27,4 @@ STARTLIST=3024 ;STARTLIST=LVF652 MAXCNC=10 + diff --git a/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini b/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini index 72bea7db..a9d47506 100644 --- a/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini +++ b/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini @@ -34,3 +34,4 @@ STARTLIST=SIMUL_01 ;STARTLIST=3026 MAXCNC=10 + diff --git a/IOB-WIN-PING/DATA/CONF/MAIN.ini b/IOB-WIN-PING/DATA/CONF/MAIN.ini index 9ca78fec..14fc4c91 100644 --- a/IOB-WIN-PING/DATA/CONF/MAIN.ini +++ b/IOB-WIN-PING/DATA/CONF/MAIN.ini @@ -21,4 +21,3 @@ STARTLIST=SIMUL_01 MAXCNC=10 - diff --git a/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini b/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini index 41774edf..839e455b 100644 --- a/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini +++ b/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini @@ -41,4 +41,5 @@ CLI_INST=SteamWareSim ;STARTLIST=SIMUL_01 STARTLIST=3010 -MAXCNC=10 + + diff --git a/IOB-WIN-WPS/DATA/CONF/MAIN.ini b/IOB-WIN-WPS/DATA/CONF/MAIN.ini index a81dc4b2..87ce4112 100644 --- a/IOB-WIN-WPS/DATA/CONF/MAIN.ini +++ b/IOB-WIN-WPS/DATA/CONF/MAIN.ini @@ -23,4 +23,5 @@ STARTLIST=3018 ;STARTLIST=3019 ;STARTLIST=SIMUL_06 -MAXCNC=10 + +