From d70bbc9e446fdc41da90e8127174d65201a7fbe0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 28 Jan 2026 10:19:38 +0100 Subject: [PATCH] =?UTF-8?q?Update=20modalit=C3=A0=20blocco=20display=20qua?= =?UTF-8?q?ndo=20hidden=20x=20ora=20su=20shelly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IOB-WIN-FORM/AdapterForm.cs | 72 +++++++++++++++++++++++++++++++------ IOB-WIN-FORM/MainForm.cs | 34 +++++++++++++++++- 2 files changed, 94 insertions(+), 12 deletions(-) diff --git a/IOB-WIN-FORM/AdapterForm.cs b/IOB-WIN-FORM/AdapterForm.cs index 57215aa3..eeba20c4 100644 --- a/IOB-WIN-FORM/AdapterForm.cs +++ b/IOB-WIN-FORM/AdapterForm.cs @@ -135,6 +135,10 @@ namespace IOB_WIN_FORM if (_commPlcActive != value) { _commPlcActive = value; + + // Se l'applicazione è minimizzata, NON invocare la UI: risparmio il Context Switch del thread grafico. + if (!ShouldUpdateUI()) return; + // se true --> comunica/verde, altrimenti grigio this.UIThread(delegate { @@ -158,6 +162,9 @@ namespace IOB_WIN_FORM set { _commSrvActive = value; + + if (!ShouldUpdateUI()) return; + this.UIThread(delegate { switch (value) @@ -239,10 +246,12 @@ namespace IOB_WIN_FORM } if (dMonDisplVetoVeto[0] < adesso) { - // se scaduto veto --> display! - lblRawData.Text = String.Join(Environment.NewLine, dMonValues[0]); // update veto! dMonDisplVetoVeto[0] = adesso.AddMilliseconds(delayShowLogMs); + + if (!ShouldUpdateUI()) return; + // se scaduto veto --> display! + lblRawData.Text = String.Join(Environment.NewLine, dMonValues[0]); } } } @@ -264,10 +273,12 @@ namespace IOB_WIN_FORM } if (dMonDisplVetoVeto[1] < adesso) { - // se scaduto veto --> display! - lblOutMessage.Text = String.Join(Environment.NewLine, dMonValues[1]); // update veto! dMonDisplVetoVeto[1] = adesso.AddMilliseconds(delayShowLogMs); + + if (!ShouldUpdateUI()) return; + // se scaduto veto --> display! + lblOutMessage.Text = String.Join(Environment.NewLine, dMonValues[1]); } } } @@ -289,10 +300,12 @@ namespace IOB_WIN_FORM } if (dMonDisplVetoVeto[2] < adesso) { - // se scaduto veto --> display! - lblOutMessage2.Text = String.Join(Environment.NewLine, dMonValues[2]); // update veto! dMonDisplVetoVeto[2] = adesso.AddMilliseconds(delayShowLogMs); + + if (!ShouldUpdateUI()) return; + // se scaduto veto --> display! + lblOutMessage2.Text = String.Join(Environment.NewLine, dMonValues[2]); } } } @@ -314,10 +327,12 @@ namespace IOB_WIN_FORM } if (dMonDisplVetoVeto[3] < adesso) { - // se scaduto veto --> display! - lblOutMessage3.Text = String.Join(Environment.NewLine, dMonValues[3]); // update veto! dMonDisplVetoVeto[3] = adesso.AddMilliseconds(delayShowLogMs); + + if (!ShouldUpdateUI()) return; + // se scaduto veto --> display! + lblOutMessage3.Text = String.Join(Environment.NewLine, dMonValues[3]); } } } @@ -464,6 +479,7 @@ namespace IOB_WIN_FORM DateTime adesso = DateTime.Now; if (logWatchWriteVeto < adesso) { + if (!ShouldUpdateUI()) return; this.UIThread(delegate { lblLogfile.Text = string.Join(Environment.NewLine, logWatchString); @@ -571,6 +587,7 @@ namespace IOB_WIN_FORM var newColor = decSemaforo(value); if (newColor != bIN.BackColor) { + if (!ShouldUpdateUI()) return; this.UIThread(delegate { bIN.BackColor = newColor; @@ -595,6 +612,7 @@ namespace IOB_WIN_FORM var newColor = decSemaforo(value); if (newColor != bOUT.BackColor) { + if (!ShouldUpdateUI()) return; this.UIThread(delegate { bOUT.BackColor = newColor; @@ -623,6 +641,7 @@ namespace IOB_WIN_FORM { logTaskString = logTaskString.Take(nLine2show).ToList(); } + if (!ShouldUpdateUI()) return; this.UIThread(delegate { lblTaskLog.Text = string.Join(Environment.NewLine, logTaskString); @@ -776,8 +795,6 @@ namespace IOB_WIN_FORM /// public void displayTaskAndLog(string txt2show, bool forceDebug = false) { - lblStatus.Text = txt2show; - lblStatus.Invalidate(); if (forceDebug) { lgDebug(txt2show); @@ -786,6 +803,9 @@ namespace IOB_WIN_FORM { lgInfo(txt2show); } + if (!ShouldUpdateUI()) return; + lblStatus.Text = txt2show; + lblStatus.Invalidate(); } /// @@ -809,6 +829,7 @@ namespace IOB_WIN_FORM /// public void updateComStats(string txt2show) { + if (!ShouldUpdateUI()) return; lblComStats.Text = string.Format("{0} | ", txt2show); } @@ -818,6 +839,7 @@ namespace IOB_WIN_FORM /// public void updateFormDisplay(newDisplayData currDispData) { + if (!ShouldUpdateUI()) return; this.UIThread(delegate { // ciclo x ogni oggetto x caricare le innovazioni... @@ -886,6 +908,7 @@ namespace IOB_WIN_FORM public void WriteTextSafe(string text) { + if (!ShouldUpdateUI()) return; this.UIThread(delegate { // accoda messaggio in gestione @@ -1068,6 +1091,7 @@ namespace IOB_WIN_FORM /// protected void IobObj_eh_refreshed(object sender, iobRefreshedEventArgs e) { + if (!ShouldUpdateUI()) return; // aggiorno! this.UIThread(delegate { @@ -1224,6 +1248,25 @@ namespace IOB_WIN_FORM nLine2show = utils.CRI("numRowConsole"); } + /// + /// Indica se debba aggiornare o meno la UI perché minimizzata o meno + /// + /// + private bool ShouldUpdateUI() + { + // 1. Controlla se la form stessa è minimizzata + if (this.WindowState == FormWindowState.Minimized) return false; + + // 2. Se è una MDI Child, controlla se il Padre è minimizzato + if (this.MdiParent != null && this.MdiParent.WindowState == FormWindowState.Minimized) + return false; + + // 3. (Opzionale) Controlla se la form è visibile + if (!this.Visible) return false; + + return true; + } + /// /// MOstra info su coda complessiva /// @@ -1871,8 +1914,15 @@ namespace IOB_WIN_FORM /// private void MainForm_Resize(object sender, EventArgs e) { + // Verifichiamo se la finestra è appena stata ripristinata + if (this.WindowState != FormWindowState.Minimized && _lastState == FormWindowState.Minimized) + { + displayTaskAndLog("Adapter Form Restored from Minimized"); + } + _lastState = this.WindowState; } + private FormWindowState _lastState = FormWindowState.Minimized; /// /// Mostrata form /// @@ -1880,7 +1930,7 @@ namespace IOB_WIN_FORM /// private void MainForm_Shown(object sender, EventArgs e) { - displayTaskAndLog("Main Form SHOWN (Adapter)", true); + displayTaskAndLog("Adapter Form SHOWN (Adapter)", true); } private void mLoadConf_Click(object sender, EventArgs e) diff --git a/IOB-WIN-FORM/MainForm.cs b/IOB-WIN-FORM/MainForm.cs index a24fafe8..725348c3 100644 --- a/IOB-WIN-FORM/MainForm.cs +++ b/IOB-WIN-FORM/MainForm.cs @@ -86,6 +86,9 @@ namespace IOB_WIN_FORM // se true --> comunica/verde, altrimenti grigio lblApp.ForeColor = value ? Color.SeaGreen : Color.Black; lblVers.ForeColor = value ? Color.SeaGreen : Color.DarkSlateGray; + + if (!ShouldUpdateUI()) return; + this.UIThread(delegate { statusStrip1.Refresh(); @@ -181,6 +184,8 @@ namespace IOB_WIN_FORM /// public void advProgBar() { + // solo se non minimizzata + if (!ShouldUpdateUI()) return; try { // aggiorno runtime... @@ -217,9 +222,12 @@ namespace IOB_WIN_FORM /// public void displayTaskAndLog(string txt2show) { + lgInfo(txt2show); + + // mostro solo se non minimizzata + if (!ShouldUpdateUI()) return; lblStatus.Text = txt2show; lblStatus.Invalidate(); - lgInfo(txt2show); } /// @@ -245,6 +253,7 @@ namespace IOB_WIN_FORM score++; } + if (!ShouldUpdateUI()) return; switch (score) { case 0: @@ -1014,8 +1023,16 @@ namespace IOB_WIN_FORM private void MainForm_Resize(object sender, EventArgs e) { checkFormVisibility(); + // Verifichiamo se la finestra è appena stata ripristinata + if (this.WindowState != FormWindowState.Minimized && _lastState == FormWindowState.Minimized) + { + displayTaskAndLog("Main Form Restored from Minimized"); + } + _lastState = this.WindowState; } + private FormWindowState _lastState = FormWindowState.Minimized; + /// /// evento visualizzazione /// @@ -1119,6 +1136,21 @@ namespace IOB_WIN_FORM Hide(); } + private bool ShouldUpdateUI() + { + // 1. Controlla se la form stessa è minimizzata + if (this.WindowState == FormWindowState.Minimized) return false; + + // 2. Se è una MDI Child, controlla se il Padre è minimizzato + if (this.MdiParent != null && this.MdiParent.WindowState == FormWindowState.Minimized) + return false; + + // 3. (Opzionale) Controlla se la form è visibile + if (!this.Visible) return false; + + return true; + } + private void ShowLogToolStripMenuItem_Click(object sender, EventArgs e) { }