Ok con gestione riavvio threads se cambiano/calano

This commit is contained in:
Samuele Locatelli
2023-05-12 18:09:40 +02:00
parent b6fd3f15f4
commit e47906eb4a
4 changed files with 121 additions and 24 deletions
+13
View File
@@ -22,6 +22,7 @@ Partial Class ProcMan
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ProcMan))
Me.btnTestPing = New System.Windows.Forms.Button()
Me.lblpingTest = New System.Windows.Forms.Label()
@@ -39,6 +40,8 @@ Partial Class ProcMan
Me.Label1 = New System.Windows.Forms.Label()
Me.txtNumThread = New System.Windows.Forms.TextBox()
Me.lblRunning = New System.Windows.Forms.Label()
Me.TimerUI = New System.Windows.Forms.Timer(Me.components)
Me.TimerProgBar = New System.Windows.Forms.Timer(Me.components)
Me.StatusStrip1.SuspendLayout()
Me.SuspendLayout()
'
@@ -151,6 +154,7 @@ Partial Class ProcMan
'
Me.tsProgBar.Name = "tsProgBar"
Me.tsProgBar.Size = New System.Drawing.Size(100, 16)
Me.tsProgBar.Step = 1
'
'txtQueue
'
@@ -193,6 +197,13 @@ Partial Class ProcMan
Me.lblRunning.Text = "running: -"
Me.lblRunning.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'TimerUI
'
Me.TimerUI.Interval = 300
'
'TimerProgBar
'
'
'ProcMan
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
@@ -239,4 +250,6 @@ Partial Class ProcMan
Friend WithEvents Label1 As Label
Friend WithEvents txtNumThread As TextBox
Friend WithEvents lblRunning As Label
Friend WithEvents TimerUI As Timer
Friend WithEvents TimerProgBar As Timer
End Class
+6
View File
@@ -120,6 +120,12 @@
<metadata name="StatusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="TimerUI.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>134, 17</value>
</metadata>
<metadata name="TimerProgBar.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>228, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
+100 -19
View File
@@ -4,7 +4,23 @@ Imports System.Text
Imports System.Threading
Imports WebDoorCreator.SDK
Partial Public Class ProcMan
Public Class ProcMan
#Region "Public Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
synchronizationContext = SynchronizationContext.Current
StartUiThread()
startAllThreads()
End Sub
#End Region
#Region "Public Methods"
@@ -18,6 +34,7 @@ Partial Public Class ProcMan
Next
sb.AppendLine()
txtQueue.Text = sb.ToString()
txtQueue.Invalidate()
End Sub
Public Sub SetMaxCamInstances(value As Integer)
@@ -28,36 +45,34 @@ Partial Public Class ProcMan
#End Region
'Private ReadOnly synchronizationContext As SynchronizationContext
'Private Sub performBarAdvance()
' synchronizationContext.Post(New SendOrPostCallback(Function(o)
' tsProgBar.PerformStep()
' If tsProgBar.Value >= tsProgBar.Maximum Then tsProgBar.Value = 0 End If
' tsProgBar.Invalidate()
' End Function), "")
'End Sub
#Region "Private Fields"
Private ReadOnly synchronizationContext As SynchronizationContext
' caricamento del NEXT STACK da redis (come oggetto) PROD http : https://iis01.egalware.com/WDC/SRV/
' DEV: https : https://localhost:7043/
Dim baseIp As String = "iis01.egalware.com"
Dim baseUrl As String = "https://iis01.egalware.com/WDC/SRV/"
Dim codPost As String = "WRK001" ' nome macchina calcolo
Dim codPost As String = "WRK001"
' nome macchina calcolo
Dim currWDC As WDC = New WDC(baseIp, baseUrl, codPost)
Dim idxSim As Integer = 0
Dim m_bExecutionThreadStoped As Boolean = False
Dim m_bStopProcess As Boolean = False
Dim m_ExecutionThread As Thread
'Private m_MaxCamInstances As Integer = 8
Private m_MaxCamInstances As Integer = 1
Dim risultatoPing As PingReply = Nothing
Dim ThreadList As Thread()
#End Region
@@ -179,7 +194,8 @@ Partial Public Class ProcMan
If bOk Then
bOk = currWDC.testAlive
End If
Else bOk = True
Else
bOk = True
End If
' se connessione non ok o processo fermato, fermo i thread
If Not bOk OrElse bStopMainProcess Then
@@ -229,6 +245,7 @@ Partial Public Class ProcMan
n30SecCounter = 1
End If
Thread.Sleep(1000)
End While
End Sub
@@ -247,6 +264,36 @@ Partial Public Class ProcMan
Return bOk
End Function
Private Sub performBarAdvance()
synchronizationContext.Post(New SendOrPostCallback(
Sub(o)
tsProgBar.PerformStep()
If tsProgBar.Value >= tsProgBar.Maximum Then
tsProgBar.Value = 0
End If
tsProgBar.Invalidate()
End Sub
), "")
End Sub
Private Sub performUpdateUI()
synchronizationContext.Post(New SendOrPostCallback(
Sub(o)
lblRunning.Text = $"threads: {ThreadCount()}/{m_MaxCamInstances}"
lblRunning.Invalidate()
DisplayQueueStatus()
'verifico thread attivi e se calano --> riavvia..
If ThreadCount() <> m_MaxCamInstances Then
stopAllThreads()
Thread.Sleep(100)
startAllThreads()
End If
End Sub
), "")
End Sub
Private Sub startAllThreads()
m_bStopProcess = False
' fix colori
@@ -261,6 +308,9 @@ Partial Public Class ProcMan
' avvio thread di gestione della macchina che avvia la connessione
m_ExecutionThread.Start()
' avvio il timer di refresh
TimerProgBar.Enabled = True
TimerProgBar.Start()
#If False Then
'' recupero Id dei DDF
'Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf"
@@ -494,6 +544,12 @@ Partial Public Class ProcMan
startAllThreads()
End Sub
Private Sub StartUiThread()
' avvio timer progBar
TimerUI.Enabled = True
TimerUI.Start()
End Sub
Private Sub stopAllThreads()
m_bStopProcess = True
' fix colori
@@ -504,12 +560,29 @@ Partial Public Class ProcMan
Thread.Sleep(10)
End While
m_ExecutionThread = Nothing
' fix timer
TimerProgBar.Enabled = False
TimerProgBar.Stop()
End Sub
Private Sub StopProcess_Click(sender As Object, e As EventArgs) Handles StopProcess.Click
stopAllThreads()
End Sub
Private Function ThreadCount() As Integer
Dim numCount = 0
If Not IsNothing(ThreadList) Then
' conto i NON nulli
For Each Thread In ThreadList
If Not IsNothing(Thread) Then
numCount += 1
End If
Next
End If
' rendo
Return numCount
End Function
Private Sub ThreadFunction()
Dim sExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe"
@@ -586,17 +659,25 @@ Partial Public Class ProcMan
End Sub
Private Sub TimerProgBar_Tick(sender As Object, e As EventArgs) Handles TimerProgBar.Tick
' esegue refresh prog bar
performBarAdvance()
End Sub
Private Sub TimerUI_Tick(sender As Object, e As EventArgs) Handles TimerUI.Tick
' effettuo refresh code e status thread
performUpdateUI()
End Sub
Private Sub txtNumThread_TextChanged(sender As Object, e As EventArgs) Handles txtNumThread.TextChanged
Dim numReq As Integer = 1
Integer.TryParse(txtNumThread.Text, numReq)
' controllo se cambiato il num thread
If numReq <> m_MaxCamInstances Then
stopAllThreads()
startAllThreads()
SetMaxCamInstances(numReq)
'startAllThreads()
End If
SetMaxCamInstances(numReq)
End Sub
#End Region
+2 -5
View File
@@ -63,11 +63,8 @@ namespace WebDoorCreator.SDK
try
{
var rawData = callUrlGet(urlAlive);
if (rawData != "ERR")
{
string returnData = JsonConvert.DeserializeObject<string>(rawData);
answ = returnData == "OK";
}
string returnData = JsonConvert.DeserializeObject<string>(rawData);
answ = returnData == "OK";
}
catch
{ }