From 0dfe90ec9593bc34aaf1bbe4e294eddc6f103919 Mon Sep 17 00:00:00 2001 From: Emmanuele Sassi Date: Mon, 15 May 2023 17:29:14 +0200 Subject: [PATCH 1/3] - aggiunto stato corrente dei thread --- WebDoorCreator.CamSrv/ProcMan.Designer.vb | 141 ++-- WebDoorCreator.CamSrv/ProcMan.vb | 911 +++++++++++----------- 2 files changed, 560 insertions(+), 492 deletions(-) diff --git a/WebDoorCreator.CamSrv/ProcMan.Designer.vb b/WebDoorCreator.CamSrv/ProcMan.Designer.vb index 2fdb5c9..a88f397 100644 --- a/WebDoorCreator.CamSrv/ProcMan.Designer.vb +++ b/WebDoorCreator.CamSrv/ProcMan.Designer.vb @@ -50,15 +50,19 @@ Partial Class ProcMan Me.btnExportStats = New System.Windows.Forms.Button() Me.chkAutoRestart = New System.Windows.Forms.CheckBox() Me.TimerCheck = New System.Windows.Forms.Timer(Me.components) + Me.ThreadCurrentStatusList = New System.Windows.Forms.ListView() + Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) Me.StatusStrip1.SuspendLayout() Me.GroupBox1.SuspendLayout() Me.SuspendLayout() ' 'btnTestPing ' - Me.btnTestPing.Location = New System.Drawing.Point(13, 13) + Me.btnTestPing.Location = New System.Drawing.Point(17, 16) + Me.btnTestPing.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.btnTestPing.Name = "btnTestPing" - Me.btnTestPing.Size = New System.Drawing.Size(75, 23) + Me.btnTestPing.Size = New System.Drawing.Size(100, 28) Me.btnTestPing.TabIndex = 0 Me.btnTestPing.Text = "Test Ping" Me.btnTestPing.UseVisualStyleBackColor = True @@ -66,35 +70,39 @@ Partial Class ProcMan 'lblpingTest ' Me.lblpingTest.AutoSize = True - Me.lblpingTest.Location = New System.Drawing.Point(115, 18) + Me.lblpingTest.Location = New System.Drawing.Point(153, 22) + Me.lblpingTest.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) Me.lblpingTest.Name = "lblpingTest" - Me.lblpingTest.Size = New System.Drawing.Size(25, 13) + Me.lblpingTest.Size = New System.Drawing.Size(28, 16) Me.lblpingTest.TabIndex = 1 Me.lblpingTest.Text = "???" ' 'lblTestAlive ' Me.lblTestAlive.AutoSize = True - Me.lblTestAlive.Location = New System.Drawing.Point(274, 18) + Me.lblTestAlive.Location = New System.Drawing.Point(365, 22) + Me.lblTestAlive.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) Me.lblTestAlive.Name = "lblTestAlive" - Me.lblTestAlive.Size = New System.Drawing.Size(25, 13) + Me.lblTestAlive.Size = New System.Drawing.Size(28, 16) Me.lblTestAlive.TabIndex = 3 Me.lblTestAlive.Text = "???" ' 'btnTestAlive ' - Me.btnTestAlive.Location = New System.Drawing.Point(172, 13) + Me.btnTestAlive.Location = New System.Drawing.Point(229, 16) + Me.btnTestAlive.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.btnTestAlive.Name = "btnTestAlive" - Me.btnTestAlive.Size = New System.Drawing.Size(75, 23) + Me.btnTestAlive.Size = New System.Drawing.Size(100, 28) Me.btnTestAlive.TabIndex = 2 Me.btnTestAlive.Text = "Test Alive" Me.btnTestAlive.UseVisualStyleBackColor = True ' 'btnResetQueue ' - Me.btnResetQueue.Location = New System.Drawing.Point(13, 163) + Me.btnResetQueue.Location = New System.Drawing.Point(17, 201) + Me.btnResetQueue.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.btnResetQueue.Name = "btnResetQueue" - Me.btnResetQueue.Size = New System.Drawing.Size(75, 23) + Me.btnResetQueue.Size = New System.Drawing.Size(100, 28) Me.btnResetQueue.TabIndex = 6 Me.btnResetQueue.Text = "Reset Q" Me.btnResetQueue.UseVisualStyleBackColor = True @@ -102,84 +110,93 @@ Partial Class ProcMan 'txtOut ' Me.txtOut.BackColor = System.Drawing.SystemColors.ControlDarkDark - Me.txtOut.Font = New System.Drawing.Font("Roboto", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.txtOut.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtOut.ForeColor = System.Drawing.Color.Yellow - Me.txtOut.Location = New System.Drawing.Point(12, 195) - Me.txtOut.MinimumSize = New System.Drawing.Size(60, 120) + Me.txtOut.Location = New System.Drawing.Point(16, 240) + Me.txtOut.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.txtOut.MinimumSize = New System.Drawing.Size(79, 147) Me.txtOut.Multiline = True Me.txtOut.Name = "txtOut" - Me.txtOut.Size = New System.Drawing.Size(75, 141) + Me.txtOut.Size = New System.Drawing.Size(99, 173) Me.txtOut.TabIndex = 7 Me.txtOut.Text = "---" ' 'btnQueueStatus ' - Me.btnQueueStatus.Location = New System.Drawing.Point(13, 64) + Me.btnQueueStatus.Location = New System.Drawing.Point(17, 79) + Me.btnQueueStatus.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.btnQueueStatus.Name = "btnQueueStatus" - Me.btnQueueStatus.Size = New System.Drawing.Size(75, 23) + Me.btnQueueStatus.Size = New System.Drawing.Size(100, 28) Me.btnQueueStatus.TabIndex = 8 Me.btnQueueStatus.Text = "Stato Queue" Me.btnQueueStatus.UseVisualStyleBackColor = True ' 'StartProcess ' - Me.StartProcess.Location = New System.Drawing.Point(13, 19) + Me.StartProcess.Location = New System.Drawing.Point(17, 23) + Me.StartProcess.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.StartProcess.Name = "StartProcess" - Me.StartProcess.Size = New System.Drawing.Size(75, 23) + Me.StartProcess.Size = New System.Drawing.Size(100, 28) Me.StartProcess.TabIndex = 9 Me.StartProcess.Text = "Start" Me.StartProcess.UseVisualStyleBackColor = True ' 'StopProcess ' - Me.StopProcess.Location = New System.Drawing.Point(244, 18) + Me.StopProcess.Location = New System.Drawing.Point(325, 22) + Me.StopProcess.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.StopProcess.Name = "StopProcess" - Me.StopProcess.Size = New System.Drawing.Size(75, 23) + Me.StopProcess.Size = New System.Drawing.Size(100, 28) Me.StopProcess.TabIndex = 10 Me.StopProcess.Text = "Stop" Me.StopProcess.UseVisualStyleBackColor = True ' 'StatusStrip1 ' + Me.StatusStrip1.ImageScalingSize = New System.Drawing.Size(20, 20) Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tsProgBar}) - Me.StatusStrip1.Location = New System.Drawing.Point(0, 423) + Me.StatusStrip1.Location = New System.Drawing.Point(0, 523) Me.StatusStrip1.Name = "StatusStrip1" - Me.StatusStrip1.Size = New System.Drawing.Size(552, 22) + Me.StatusStrip1.Padding = New System.Windows.Forms.Padding(1, 0, 19, 0) + Me.StatusStrip1.Size = New System.Drawing.Size(736, 25) Me.StatusStrip1.TabIndex = 11 Me.StatusStrip1.Text = "StatusStrip1" ' 'tsProgBar ' Me.tsProgBar.Name = "tsProgBar" - Me.tsProgBar.Size = New System.Drawing.Size(100, 16) + Me.tsProgBar.Size = New System.Drawing.Size(133, 17) Me.tsProgBar.Step = 1 ' 'txtQueue ' Me.txtQueue.BackColor = System.Drawing.SystemColors.ControlDarkDark - Me.txtQueue.Font = New System.Drawing.Font("Roboto", 7.0!) + Me.txtQueue.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!) Me.txtQueue.ForeColor = System.Drawing.SystemColors.Window - Me.txtQueue.Location = New System.Drawing.Point(13, 93) + Me.txtQueue.Location = New System.Drawing.Point(17, 114) + Me.txtQueue.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.txtQueue.Multiline = True Me.txtQueue.Name = "txtQueue" - Me.txtQueue.Size = New System.Drawing.Size(75, 64) + Me.txtQueue.Size = New System.Drawing.Size(99, 78) Me.txtQueue.TabIndex = 12 Me.txtQueue.Text = "Q Status:" ' 'Label1 ' Me.Label1.AutoSize = True - Me.Label1.Location = New System.Drawing.Point(99, 24) + Me.Label1.Location = New System.Drawing.Point(132, 30) + Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) Me.Label1.Name = "Label1" - Me.Label1.Size = New System.Drawing.Size(30, 13) + Me.Label1.Size = New System.Drawing.Size(35, 16) Me.Label1.TabIndex = 13 Me.Label1.Text = "num:" ' 'txtNumThread ' - Me.txtNumThread.Location = New System.Drawing.Point(128, 21) + Me.txtNumThread.Location = New System.Drawing.Point(171, 26) + Me.txtNumThread.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.txtNumThread.Name = "txtNumThread" - Me.txtNumThread.Size = New System.Drawing.Size(32, 20) + Me.txtNumThread.Size = New System.Drawing.Size(41, 22) Me.txtNumThread.TabIndex = 14 Me.txtNumThread.Text = "1" Me.txtNumThread.TextAlign = System.Windows.Forms.HorizontalAlignment.Right @@ -187,10 +204,11 @@ Partial Class ProcMan 'lblRunning ' Me.lblRunning.AutoSize = True - Me.lblRunning.Location = New System.Drawing.Point(166, 24) - Me.lblRunning.MinimumSize = New System.Drawing.Size(75, 0) + Me.lblRunning.Location = New System.Drawing.Point(221, 30) + Me.lblRunning.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) + Me.lblRunning.MinimumSize = New System.Drawing.Size(100, 0) Me.lblRunning.Name = "lblRunning" - Me.lblRunning.Size = New System.Drawing.Size(75, 13) + Me.lblRunning.Size = New System.Drawing.Size(100, 16) Me.lblRunning.TabIndex = 15 Me.lblRunning.Text = "running: -" Me.lblRunning.TextAlign = System.Drawing.ContentAlignment.MiddleCenter @@ -206,9 +224,10 @@ Partial Class ProcMan ' Me.LISTThreadStatus.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.chThread, Me.chTime, Me.chOther}) Me.LISTThreadStatus.HideSelection = False - Me.LISTThreadStatus.Location = New System.Drawing.Point(13, 48) + Me.LISTThreadStatus.Location = New System.Drawing.Point(17, 59) + Me.LISTThreadStatus.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.LISTThreadStatus.Name = "LISTThreadStatus" - Me.LISTThreadStatus.Size = New System.Drawing.Size(403, 302) + Me.LISTThreadStatus.Size = New System.Drawing.Size(536, 173) Me.LISTThreadStatus.TabIndex = 16 Me.LISTThreadStatus.UseCompatibleStateImageBehavior = False Me.LISTThreadStatus.View = System.Windows.Forms.View.Details @@ -230,6 +249,7 @@ Partial Class ProcMan ' 'GroupBox1 ' + Me.GroupBox1.Controls.Add(Me.ThreadCurrentStatusList) Me.GroupBox1.Controls.Add(Me.chkStatAggr) Me.GroupBox1.Controls.Add(Me.LISTThreadStatus) Me.GroupBox1.Controls.Add(Me.lblRunning) @@ -237,9 +257,11 @@ Partial Class ProcMan Me.GroupBox1.Controls.Add(Me.StopProcess) Me.GroupBox1.Controls.Add(Me.Label1) Me.GroupBox1.Controls.Add(Me.StartProcess) - Me.GroupBox1.Location = New System.Drawing.Point(118, 64) + Me.GroupBox1.Location = New System.Drawing.Point(157, 79) + Me.GroupBox1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.GroupBox1.Name = "GroupBox1" - Me.GroupBox1.Size = New System.Drawing.Size(422, 356) + Me.GroupBox1.Padding = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.GroupBox1.Size = New System.Drawing.Size(563, 438) Me.GroupBox1.TabIndex = 17 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Threads" @@ -249,18 +271,20 @@ Partial Class ProcMan Me.chkStatAggr.AutoSize = True Me.chkStatAggr.Checked = True Me.chkStatAggr.CheckState = System.Windows.Forms.CheckState.Checked - Me.chkStatAggr.Location = New System.Drawing.Point(326, 21) + Me.chkStatAggr.Location = New System.Drawing.Point(435, 26) + Me.chkStatAggr.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.chkStatAggr.Name = "chkStatAggr" - Me.chkStatAggr.Size = New System.Drawing.Size(75, 17) + Me.chkStatAggr.Size = New System.Drawing.Size(91, 20) Me.chkStatAggr.TabIndex = 17 Me.chkStatAggr.Text = "Aggr Stats" Me.chkStatAggr.UseVisualStyleBackColor = True ' 'btnExportStats ' - Me.btnExportStats.Location = New System.Drawing.Point(459, 13) + Me.btnExportStats.Location = New System.Drawing.Point(612, 16) + Me.btnExportStats.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.btnExportStats.Name = "btnExportStats" - Me.btnExportStats.Size = New System.Drawing.Size(75, 23) + Me.btnExportStats.Size = New System.Drawing.Size(100, 28) Me.btnExportStats.TabIndex = 18 Me.btnExportStats.Text = "Export Stats" Me.btnExportStats.UseVisualStyleBackColor = True @@ -270,9 +294,10 @@ Partial Class ProcMan Me.chkAutoRestart.AutoSize = True Me.chkAutoRestart.Checked = True Me.chkAutoRestart.CheckState = System.Windows.Forms.CheckState.Checked - Me.chkAutoRestart.Location = New System.Drawing.Point(349, 17) + Me.chkAutoRestart.Location = New System.Drawing.Point(465, 21) + Me.chkAutoRestart.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.chkAutoRestart.Name = "chkAutoRestart" - Me.chkAutoRestart.Size = New System.Drawing.Size(82, 17) + Me.chkAutoRestart.Size = New System.Drawing.Size(99, 20) Me.chkAutoRestart.TabIndex = 19 Me.chkAutoRestart.Text = "AutoRestart" Me.chkAutoRestart.UseVisualStyleBackColor = True @@ -281,11 +306,33 @@ Partial Class ProcMan ' Me.TimerCheck.Interval = 30000 ' + 'ThreadCurrentStatusList + ' + Me.ThreadCurrentStatusList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2}) + Me.ThreadCurrentStatusList.HideSelection = False + Me.ThreadCurrentStatusList.Location = New System.Drawing.Point(17, 257) + Me.ThreadCurrentStatusList.Margin = New System.Windows.Forms.Padding(4) + Me.ThreadCurrentStatusList.Name = "ThreadCurrentStatusList" + Me.ThreadCurrentStatusList.Size = New System.Drawing.Size(536, 173) + Me.ThreadCurrentStatusList.TabIndex = 18 + Me.ThreadCurrentStatusList.UseCompatibleStateImageBehavior = False + Me.ThreadCurrentStatusList.View = System.Windows.Forms.View.Details + ' + 'ColumnHeader1 + ' + Me.ColumnHeader1.Text = "Thread" + Me.ColumnHeader1.Width = 100 + ' + 'ColumnHeader2 + ' + Me.ColumnHeader2.Text = "Status" + Me.ColumnHeader2.Width = 100 + ' 'ProcMan ' - Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(552, 445) + Me.ClientSize = New System.Drawing.Size(736, 548) Me.Controls.Add(Me.chkAutoRestart) Me.Controls.Add(Me.btnExportStats) Me.Controls.Add(Me.GroupBox1) @@ -299,6 +346,7 @@ Partial Class ProcMan Me.Controls.Add(Me.lblpingTest) Me.Controls.Add(Me.btnTestPing) Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) + Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) Me.Name = "ProcMan" Me.Text = "MainForm" Me.StatusStrip1.ResumeLayout(False) @@ -336,4 +384,7 @@ Partial Class ProcMan Friend WithEvents btnExportStats As Button Friend WithEvents chkAutoRestart As CheckBox Friend WithEvents TimerCheck As Timer + Friend WithEvents ThreadCurrentStatusList As ListView + Friend WithEvents ColumnHeader1 As ColumnHeader + Friend WithEvents ColumnHeader2 As ColumnHeader End Class diff --git a/WebDoorCreator.CamSrv/ProcMan.vb b/WebDoorCreator.CamSrv/ProcMan.vb index a173a93..d24ff2e 100644 --- a/WebDoorCreator.CamSrv/ProcMan.vb +++ b/WebDoorCreator.CamSrv/ProcMan.vb @@ -8,257 +8,273 @@ Public Class ProcMan #Region "Public Constructors" - Public Sub New() + Public Sub New() - ' This call is required by the designer. - InitializeComponent() + ' This call is required by the designer. + InitializeComponent() - ' Add any initialization after the InitializeComponent() call. - synchronizationContext = SynchronizationContext.Current - ' preparo lista thread... - 'Begin the update - LISTThreadStatus.BeginUpdate() - 'clear the List - LISTThreadStatus.Items.Clear() - 'Add init - LISTThreadStatus.Items.Add(New ListViewItem(New String() {"init", "waiting", "-"})) - 'End the update - LISTThreadStatus.EndUpdate() - StartUiThread() - startAllThreads() - CheckStartAutoRestart() + ' Add any initialization after the InitializeComponent() call. + synchronizationContext = SynchronizationContext.Current + ' preparo lista thread... + 'Begin the update + LISTThreadStatus.BeginUpdate() + 'clear the List + LISTThreadStatus.Items.Clear() + 'Add init + LISTThreadStatus.Items.Add(New ListViewItem(New String() {"init", "waiting", "-"})) + 'End the update + LISTThreadStatus.EndUpdate() + StartUiThread() + startAllThreads() + CheckStartAutoRestart() - End Sub + End Sub #End Region #Region "Private Fields" - Private ReadOnly synchronizationContext As SynchronizationContext + 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" + ' 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 baseUrl As String = "https://iis01.egalware.com/WDC/SRV/" - Dim codPost As String = "WRK001" + Dim codPost As String = "WRK001" - ' nome macchina calcolo - Dim currWDC As WDC = New WDC(baseIp, baseUrl, codPost) + ' nome macchina calcolo + Dim currWDC As WDC = New WDC(baseIp, baseUrl, codPost) - Dim idxSim As Integer = 0 + Dim idxSim As Integer = 0 - Dim m_bExecutionThreadStoped As Boolean = False + Dim m_bExecutionThreadStoped As Boolean = False - Dim m_bStopProcess As Boolean = False + Dim m_bStopProcess As Boolean = False - Dim m_ExecutionThread As Thread + Dim m_ExecutionThread As Thread - 'Private m_MaxCamInstances As Integer = 8 - Private m_MaxCamInstances As Integer = 1 + 'Private m_MaxCamInstances As Integer = 8 + Private m_MaxCamInstances As Integer = 1 - Dim risultatoPing As PingReply = Nothing + Dim risultatoPing As PingReply = Nothing - Dim ThreadList As Thread() + Dim ThreadList As Thread() #End Region #Region "Private Methods" - Private Sub btnQueueStatus_Click(sender As Object, e As EventArgs) Handles btnQueueStatus.Click - DisplayQueueStatus() - End Sub + Private Sub UpdateThreadCurrentStatus() + synchronizationContext.Post(New SendOrPostCallback( + Sub(o) + ThreadCurrentStatusList.BeginUpdate() + ThreadCurrentStatusList.Items.Clear() - Private Sub btnResetQueue_Click(sender As Object, e As EventArgs) Handles btnResetQueue.Click - currWDC.ResetQueue() - txtOut.Text = "Queue Resetted!" - End Sub + If Not IsNothing(ThreadList) Then + For ThreadIndex = 0 To ThreadList.Count - 1 + ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, If(Not IsNothing(ThreadList(ThreadIndex)), ThreadList(ThreadIndex).ThreadState.ToString(), "nothing")})) + Next + End If + ThreadCurrentStatusList.EndUpdate() - Private Sub btnTestAlive_Click(sender As Object, e As EventArgs) Handles btnTestAlive.Click - Dim answ As String = "" - If (currWDC.testAlive) Then - lblTestAlive.Text = "Server Alive!!!" - Else - lblTestAlive.Text = "Alive test failed!" - End If - End Sub + End Sub), "") + End Sub - Private Sub btnTestPing_Click(sender As Object, e As EventArgs) Handles btnTestPing.Click - ' chiamo test ping... - risultatoPing = currWDC.testPing - lblpingTest.Text = risultatoPing.Status.ToString() - End Sub + Private Sub btnQueueStatus_Click(sender As Object, e As EventArgs) Handles btnQueueStatus.Click + DisplayQueueStatus() + End Sub - Private Sub DisplayQueueStatus() - Dim queueStatus As New Dictionary(Of String, Long) - queueStatus = currWDC.queueStatus - Dim sb As StringBuilder - sb = New StringBuilder - For Each item As KeyValuePair(Of String, Long) In queueStatus - sb.AppendLine($"{item.Key}: {item.Value}") - Next - sb.AppendLine() - txtQueue.Text = sb.ToString() - txtQueue.Invalidate() - End Sub + Private Sub btnResetQueue_Click(sender As Object, e As EventArgs) Handles btnResetQueue.Click + currWDC.ResetQueue() + txtOut.Text = "Queue Resetted!" + End Sub - Private Sub ExecutionProcess() - ' recupero Id dei DDF - Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf" - Dim sCurrDdfDir As String = "" - Dim nDdfId As Integer = 1 + Private Sub btnTestAlive_Click(sender As Object, e As EventArgs) Handles btnTestAlive.Click + Dim answ As String = "" + If (currWDC.testAlive) Then + lblTestAlive.Text = "Server Alive!!!" + Else + lblTestAlive.Text = "Alive test failed!" + End If + End Sub - Dim bStopMainProcess As Boolean = False - Dim n30SecCounter As Integer = 0 - While Not bStopMainProcess - bStopMainProcess = m_bStopProcess - Dim bOk As Boolean = False - While Not bOk - ' ogni 30 secondi - If n30SecCounter = 30 OrElse n30SecCounter = 0 Then - ' verifica connessione - Dim risultatoPing As PingReply = currWDC.testPing - bOk = risultatoPing.Status = IPStatus.Success - If bOk Then - bOk = currWDC.testAlive - End If - Else - bOk = True - End If - ' se connessione non ok o processo fermato, fermo i thread - If Not bOk OrElse bStopMainProcess Then - If Not IsNothing(ThreadList) AndAlso ThreadList.Count > 0 AndAlso Not IsNothing(ThreadList(0)) Then - ' li fermo - m_bStopProcess = True - ' verifico siano terminati - Dim bOneNotEnded As Boolean = True - While bOneNotEnded - bOneNotEnded = False - For Each Thread In ThreadList - If Not IsNothing(Thread) Then - If Thread.IsAlive Then - bOneNotEnded = True - End If - End If - Next - End While - ' pulisco la lista - For ThreadIndex = 0 To ThreadList.Count - 1 - ThreadList(ThreadIndex) = Nothing - Next - End If - If bStopMainProcess Then - m_bExecutionThreadStoped = True - Return - End If - End If - If Not bOk Then Thread.Sleep(10) - End While + Private Sub btnTestPing_Click(sender As Object, e As EventArgs) Handles btnTestPing.Click + ' chiamo test ping... + risultatoPing = currWDC.testPing + lblpingTest.Text = risultatoPing.Status.ToString() + End Sub - If bOk AndAlso (IsNothing(ThreadList) OrElse ThreadList.Count = 0 OrElse IsNothing(ThreadList(0))) Then - ThreadList = New Thread(m_MaxCamInstances) {} - For nThreadIndex = 0 To m_MaxCamInstances - 1 - ThreadList(nThreadIndex) = New Thread(Sub() - ThreadFunction() - End Sub) - ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA) - ' avvio thread di gestione della macchina che avvia la connessione - ThreadList(nThreadIndex).Start() - Thread.Sleep(10) - Next - End If - If n30SecCounter <= 30 Then - n30SecCounter += 1 + Private Sub DisplayQueueStatus() + Dim queueStatus As New Dictionary(Of String, Long) + queueStatus = currWDC.queueStatus + Dim sb As StringBuilder + sb = New StringBuilder + For Each item As KeyValuePair(Of String, Long) In queueStatus + sb.AppendLine($"{item.Key}: {item.Value}") + Next + sb.AppendLine() + txtQueue.Text = sb.ToString() + txtQueue.Invalidate() + End Sub + + Private Sub ExecutionProcess() + ' recupero Id dei DDF + Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf" + Dim sCurrDdfDir As String = "" + Dim nDdfId As Integer = 1 + + Dim bStopMainProcess As Boolean = False + Dim n30SecCounter As Integer = 0 + While Not bStopMainProcess + bStopMainProcess = m_bStopProcess + Dim bOk As Boolean = False + While Not bOk + ' ogni 30 secondi + If n30SecCounter = 30 OrElse n30SecCounter = 0 Then + ' verifica connessione + Dim risultatoPing As PingReply = currWDC.testPing + bOk = risultatoPing.Status = IPStatus.Success + If bOk Then + bOk = currWDC.testAlive + End If Else - n30SecCounter = 1 + bOk = True End If - Thread.Sleep(1000) + ' se connessione non ok o processo fermato, fermo i thread + If Not bOk OrElse bStopMainProcess Then + If Not IsNothing(ThreadList) AndAlso ThreadList.Count > 0 AndAlso Not IsNothing(ThreadList(0)) Then + ' li fermo + m_bStopProcess = True + ' verifico siano terminati + Dim bOneNotEnded As Boolean = True + While bOneNotEnded + bOneNotEnded = False + For Each Thread In ThreadList + If Not IsNothing(Thread) Then + If Thread.IsAlive Then + bOneNotEnded = True + End If + End If + Next + End While + ' pulisco la lista + For ThreadIndex = 0 To ThreadList.Count - 1 + ThreadList(ThreadIndex) = Nothing + Next + End If + If bStopMainProcess Then + m_bExecutionThreadStoped = True + Return + End If + End If + If Not bOk Then Thread.Sleep(10) + End While - End While + If bOk AndAlso (IsNothing(ThreadList) OrElse ThreadList.Count = 0 OrElse IsNothing(ThreadList(0))) Then + ThreadList = New Thread(m_MaxCamInstances - 1) {} + For nThreadIndex = 0 To m_MaxCamInstances - 1 + ThreadList(nThreadIndex) = New Thread(Sub() + ThreadFunction() + End Sub) + ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA) + ' avvio thread di gestione della macchina che avvia la connessione + ThreadList(nThreadIndex).Start() + Thread.Sleep(10) + Next + End If + If n30SecCounter <= 30 Then + n30SecCounter += 1 + Else + n30SecCounter = 1 + End If + Thread.Sleep(1000) - End Sub + End While - Private Function GetFileContent(ByVal filePath As String, ByRef fileContent As String) As Boolean + End Sub - Dim bOk As Boolean = File.Exists(filePath) - If bOk Then - Try - fileContent = File.ReadAllText(filePath) - Catch ex As Exception - bOk = False - fileContent = "" - End Try - End If - Return bOk - End Function + Private Function GetFileContent(ByVal filePath As String, ByRef fileContent As String) As Boolean - Private Sub performBarAdvance() - synchronizationContext.Post(New SendOrPostCallback( - Sub(o) - tsProgBar.PerformStep() - If tsProgBar.Value >= tsProgBar.Maximum Then - tsProgBar.Value = 0 - End If + Dim bOk As Boolean = File.Exists(filePath) + If bOk Then + Try + fileContent = File.ReadAllText(filePath) + Catch ex As Exception + bOk = False + fileContent = "" + End Try + End If + Return bOk + End Function - tsProgBar.Invalidate() - End Sub - ), "") - End Sub + Private Sub performBarAdvance() + synchronizationContext.Post(New SendOrPostCallback( + Sub(o) + tsProgBar.PerformStep() + If tsProgBar.Value >= tsProgBar.Maximum Then + tsProgBar.Value = 0 + End If - Private Sub performUpdateUI() - synchronizationContext.Post(New SendOrPostCallback( - Sub(o) - 'verifico thread attivi e se calano --> riavvia.. - If ThreadCount() <> m_MaxCamInstances And Not m_bStopProcess Then - stopAllThreads() - Thread.Sleep(100) - startAllThreads() - End If + tsProgBar.Invalidate() + End Sub + ), "") + End Sub - lblRunning.Text = $"threads: {ThreadCount()}/{m_MaxCamInstances}" - lblRunning.Invalidate() - DisplayQueueStatus() - ' colore btn start / stop... - If m_bStopProcess Then + Private Sub performUpdateUI() + synchronizationContext.Post(New SendOrPostCallback( + Sub(o) + 'verifico thread attivi e se calano --> riavvia.. + If ThreadCount() <> m_MaxCamInstances And Not m_bStopProcess Then + stopAllThreads() + Thread.Sleep(100) + startAllThreads() + End If - StartProcess.BackColor = ButtonBase.DefaultBackColor - StartProcess.ForeColor = ButtonBase.DefaultForeColor - StopProcess.BackColor = Color.Green - StopProcess.ForeColor = Color.White - Else - StartProcess.BackColor = Color.Green - StartProcess.ForeColor = Color.White - StopProcess.BackColor = ButtonBase.DefaultBackColor - StopProcess.ForeColor = ButtonBase.DefaultForeColor - End If - End Sub - ), "") - End Sub + lblRunning.Text = $"threads: {ThreadCount()}/{m_MaxCamInstances}" + lblRunning.Invalidate() + DisplayQueueStatus() + ' colore btn start / stop... + If m_bStopProcess Then - Private Sub SetMaxCamInstances(value As Integer) - ' Numero di core logici da utilizzare (minimo tra presenti sul PC e imposti da INI) - Dim nMaxThread As Integer = Math.Min(Environment.ProcessorCount, value) - m_MaxCamInstances = nMaxThread - End Sub + StartProcess.BackColor = ButtonBase.DefaultBackColor + StartProcess.ForeColor = ButtonBase.DefaultForeColor + StopProcess.BackColor = Color.Green + StopProcess.ForeColor = Color.White + Else + StartProcess.BackColor = Color.Green + StartProcess.ForeColor = Color.White + StopProcess.BackColor = ButtonBase.DefaultBackColor + StopProcess.ForeColor = ButtonBase.DefaultForeColor + End If + End Sub + ), "") + End Sub - Private Sub startAllThreads() - m_bStopProcess = False - '' fix colori - 'StartProcess.BackColor = Color.Green - 'StartProcess.ForeColor = Color.White + Private Sub SetMaxCamInstances(value As Integer) + ' Numero di core logici da utilizzare (minimo tra presenti sul PC e imposti da INI) + Dim nMaxThread As Integer = Math.Min(Environment.ProcessorCount, value) + m_MaxCamInstances = nMaxThread + End Sub - m_ExecutionThread = New Thread(Sub() - ExecutionProcess() - End Sub) + Private Sub startAllThreads() + m_bStopProcess = False + '' fix colori + 'StartProcess.BackColor = Color.Green + 'StartProcess.ForeColor = Color.White - m_ExecutionThread.SetApartmentState(ApartmentState.STA) - ' avvio thread di gestione della macchina che avvia la connessione - m_ExecutionThread.Start() + m_ExecutionThread = New Thread(Sub() + ExecutionProcess() + End Sub) - ' avvio il timer di refresh - TimerProgBar.Enabled = True - TimerProgBar.Start() + m_ExecutionThread.SetApartmentState(ApartmentState.STA) + ' 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" @@ -486,215 +502,216 @@ Public Class ProcMan ' End If #End If - End Sub + End Sub - Private Sub StartProcess_Click(sender As Object, e As EventArgs) Handles StartProcess.Click - startAllThreads() - End Sub + Private Sub StartProcess_Click(sender As Object, e As EventArgs) Handles StartProcess.Click + startAllThreads() + End Sub - Private Sub StartUiThread() - ' avvio timer progBar - TimerUI.Enabled = True - TimerUI.Start() - End Sub + Private Sub StartUiThread() + ' avvio timer progBar + TimerUI.Enabled = True + TimerUI.Start() + End Sub - Private Sub stopAllThreads() - m_bStopProcess = True + Private Sub stopAllThreads() + m_bStopProcess = True - While Not m_bExecutionThreadStoped - Thread.Sleep(20) - End While - m_ExecutionThread = Nothing - ' fix timer - TimerProgBar.Enabled = False - TimerProgBar.Stop() - End Sub + While Not m_bExecutionThreadStoped + Thread.Sleep(20) + 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 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" - Dim sCurrDdfDir As String = "c:\EgtData\WebDoor\Ddf" - Dim stopWatch As New Stopwatch() - Dim lExeTime As Long = 0 - Dim lOtherTime As Long = 0 - - While Not m_bStopProcess - - ' se c'e' qualcosa da processare - If currWDC.numTask2proc > 0 Then - - Dim LastRequest As Dictionary(Of String, String) = currWDC.queueList(1) - If LastRequest.Count > 0 Then - Dim Item As KeyValuePair(Of String, String) = LastRequest.First() - Dim bOk As Boolean = Not IsNothing(Item) - If bOk Then - - ' avvio cronometro - 'stopWatch.Reset() - stopWatch.Restart() - ' svuoto vecchio set file della porta richiesta - Dim fileList As String() = Directory.GetFiles(sCurrDdfDir, Item.Key + ".*") - ' elimino vecchi - If Not IsNothing(fileList) Then - For Each sFile In fileList - File.Delete(sFile) - Next - End If - - ' scrivo ddf - Dim sDdfPath As String = sCurrDdfDir & "\" & Item.Key & ".ddf" - Try - File.WriteAllText(sDdfPath, Item.Value) - Catch ex As Exception - bOk = False - End Try - - If bOk Then - - ' eseguo calcolo - Dim Proc As New Process() - Proc.StartInfo.FileName = sExePath - Proc.StartInfo.Arguments = """C:\EgtData\WebDoor\Main.lua""" & " """ & sDdfPath & """" - Proc.StartInfo.UseShellExecute = False - - If Proc.Start() Then - - While Not Proc.HasExited - Thread.Sleep(1) - End While - ' salvo exe time... - stopWatch.Stop() - lExeTime = stopWatch.ElapsedMilliseconds - stopWatch.Restart() - Dim procResults As New List(Of CalcResultDTO) - Dim currRes As New CalcResultDTO - Dim fContent As String = "" - ' verifico esistenza file svg e lo carico - bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "svg"), fContent) - ' invio risposta - currRes.Validated = Proc.ExitCode = 0 AndAlso bOk - currRes.DoorIdVers = Item.Key - ' se NON fosse validato --> messo il messaggio... - If (currRes.Validated) Then - currRes.SvgGen = fContent - Else - bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "txt"), fContent) - currRes.ErrorMsg = fContent - End If - - procResults.Add(currRes) - Dim respPut As String = currWDC.SendProcResults(procResults) - - stopWatch.Stop() - lOtherTime = stopWatch.ElapsedMilliseconds - ' aggiorno thread display... - UpdateThreadList(Item.Key, lExeTime, lOtherTime) - End If - stopWatch.Stop() - - End If - End If - End If + 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 - End While + Next + End If + ' rendo + Return numCount + End Function - End Sub + Private Sub ThreadFunction() - Private Sub TimerProgBar_Tick(sender As Object, e As EventArgs) Handles TimerProgBar.Tick - ' esegue refresh prog bar - performBarAdvance() - End Sub + Dim sExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe" + Dim sCurrDdfDir As String = "c:\EgtData\WebDoor\Ddf" + Dim stopWatch As New Stopwatch() + Dim lExeTime As Long = 0 + Dim lOtherTime As Long = 0 - Private Sub TimerUI_Tick(sender As Object, e As EventArgs) Handles TimerUI.Tick - ' effettuo refresh code e status thread - performUpdateUI() - End Sub + While Not m_bStopProcess - 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() - SetMaxCamInstances(numReq) - 'startAllThreads() - End If - End Sub + ' se c'e' qualcosa da processare + If currWDC.numTask2proc > 0 Then + + Dim LastRequest As Dictionary(Of String, String) = currWDC.queueList(1) + If LastRequest.Count > 0 Then + Dim Item As KeyValuePair(Of String, String) = LastRequest.First() + Dim bOk As Boolean = Not IsNothing(Item) + If bOk Then + + ' avvio cronometro + 'stopWatch.Reset() + stopWatch.Restart() + ' svuoto vecchio set file della porta richiesta + Dim fileList As String() = Directory.GetFiles(sCurrDdfDir, Item.Key + ".*") + ' elimino vecchi + If Not IsNothing(fileList) Then + For Each sFile In fileList + File.Delete(sFile) + Next + End If + + ' scrivo ddf + Dim sDdfPath As String = sCurrDdfDir & "\" & Item.Key & ".ddf" + Try + File.WriteAllText(sDdfPath, Item.Value) + Catch ex As Exception + bOk = False + End Try + + If bOk Then + + ' eseguo calcolo + Dim Proc As New Process() + Proc.StartInfo.FileName = sExePath + Proc.StartInfo.Arguments = """C:\EgtData\WebDoor\Main.lua""" & " """ & sDdfPath & """" + Proc.StartInfo.UseShellExecute = False + + If Proc.Start() Then + + While Not Proc.HasExited + Thread.Sleep(1) + End While + ' salvo exe time... + stopWatch.Stop() + lExeTime = stopWatch.ElapsedMilliseconds + stopWatch.Restart() + Dim procResults As New List(Of CalcResultDTO) + Dim currRes As New CalcResultDTO + Dim fContent As String = "" + ' verifico esistenza file svg e lo carico + bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "svg"), fContent) + ' invio risposta + currRes.Validated = Proc.ExitCode = 0 AndAlso bOk + currRes.DoorIdVers = Item.Key + ' se NON fosse validato --> messo il messaggio... + If (currRes.Validated) Then + currRes.SvgGen = fContent + Else + bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "txt"), fContent) + currRes.ErrorMsg = fContent + End If + + procResults.Add(currRes) + Dim respPut As String = currWDC.SendProcResults(procResults) + + stopWatch.Stop() + lOtherTime = stopWatch.ElapsedMilliseconds + ' aggiorno thread display... + UpdateThreadList(Item.Key, lExeTime, lOtherTime) + End If + stopWatch.Stop() + + End If + End If + End If + End If + End While + + 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() + UpdateThreadCurrentStatus() + 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() + SetMaxCamInstances(numReq) + 'startAllThreads() + End If + End Sub - Private isUpdatingThreads As Boolean = False - ''' - ''' Esecuzione update display lista stato threads - ''' - Private Sub UpdateThreadList(tId As String, tExeCam As Long, tOther As Long) - synchronizationContext.Post(New SendOrPostCallback( - Sub(o) - If Not isUpdatingThreads Then - isUpdatingThreads = True - ProcStats.RecordData(m_MaxCamInstances, tExeCam, tOther) - ProcStats.RecordList.Enqueue((tId, tExeCam, tOther)) - 'Begin the update - LISTThreadStatus.BeginUpdate() - LISTThreadStatus.Items.Clear() + Private isUpdatingThreads As Boolean = False + ''' + ''' Esecuzione update display lista stato threads + ''' + Private Sub UpdateThreadList(tId As String, tExeCam As Long, tOther As Long) + synchronizationContext.Post(New SendOrPostCallback( + Sub(o) + If Not isUpdatingThreads Then + isUpdatingThreads = True + ProcStats.RecordData(m_MaxCamInstances, tExeCam, tOther) + ProcStats.RecordList.Enqueue((tId, tExeCam, tOther)) + 'Begin the update + LISTThreadStatus.BeginUpdate() + LISTThreadStatus.Items.Clear() - ' compilo in base al tipo di stat richiesta - If (chkStatAggr.Checked) Then - ' statistiche di sintesi - Dim sorted = From pair In ProcStats.ExeCumSum - Order By pair.Key - For Each item In sorted - LISTThreadStatus.Items.Add( - New ListViewItem(New String() {item.Key, - $"{item.Value.NumRec} x {item.Value.ExeTime / item.Value.NumRec:N2} ms", - $"{item.Value.NumRec} x {item.Value.OthTime / item.Value.NumRec:N2} ms" - })) - Next - Else - ' formato log - Dim maxItems As Integer = 15 - While ProcStats.RecordList.Count > maxItems - Dim oldItem As (String, Long, Long) = ("", 0, 0) - ProcStats.RecordList.TryDequeue(oldItem) - End While + ' compilo in base al tipo di stat richiesta + If (chkStatAggr.Checked) Then + ' statistiche di sintesi + Dim sorted = From pair In ProcStats.ExeCumSum + Order By pair.Key + For Each item In sorted + LISTThreadStatus.Items.Add( + New ListViewItem(New String() {item.Key, + $"{item.Value.NumRec} x {item.Value.ExeTime / item.Value.NumRec:N2} ms", + $"{item.Value.NumRec} x {item.Value.OthTime / item.Value.NumRec:N2} ms" + })) + Next + Else + ' formato log + Dim maxItems As Integer = 15 + While ProcStats.RecordList.Count > maxItems + Dim oldItem As (String, Long, Long) = ("", 0, 0) + ProcStats.RecordList.TryDequeue(oldItem) + End While - For Each item As (String, Long, Long) In ProcStats.RecordList.Reverse - LISTThreadStatus.Items.Add(New ListViewItem(New String() { - item.Item1, - $"{item.Item2} ms", - $"{item.Item3} ms" - })) - Next + For Each item As (String, Long, Long) In ProcStats.RecordList.Reverse + LISTThreadStatus.Items.Add(New ListViewItem(New String() { + item.Item1, + $"{item.Item2} ms", + $"{item.Item3} ms" + })) + Next - End If - - 'End the update - LISTThreadStatus.EndUpdate() - isUpdatingThreads = False End If - End Sub - ), "") - End Sub + 'End the update + LISTThreadStatus.EndUpdate() + isUpdatingThreads = False + End If + End Sub + ), "") + + End Sub #End Region @@ -740,72 +757,72 @@ Public Class ProcMan #Region "Private Structs" - Private Structure MyProc + Private Structure MyProc #Region "Public Fields" - Public bEnable As Boolean - Public nBar As Integer - Public Proc As Process - Public Thread As Thread + Public bEnable As Boolean + Public nBar As Integer + Public Proc As Process + Public Thread As Thread #End Region - End Structure + End Structure - ''' - ''' Esportazione statistiche attuali esecuzione - ''' - ''' - ''' - Private Sub btnExportStats_Click(sender As Object, e As EventArgs) Handles btnExportStats.Click - ' statistiche di sintesi - Dim sorted = From pair In ProcStats.ExeCumSum - Order By pair.Key - ' preparo il file export... - Dim fileName As String - Dim adesso As DateTime = DateTime.Now - fileName = Path.Combine("C:\Temp\", $"WDC_Stats_{adesso:yyyyMMdd-HHmmss}.csv") - Dim sb As StringBuilder = New StringBuilder - sb.AppendLine("Threads;Samples;ExeTime;OtherTime;FullTime") - For Each item In sorted - ' preparo la linea CSV... - sb.AppendLine($"{item.Key};{item.Value.NumRec};{item.Value.ExeTime / item.Value.NumRec:N2};{item.Value.OthTime / item.Value.NumRec:N2};{(item.Value.ExeTime + item.Value.OthTime) / item.Key:N2}") - Next - ' scrivo! - File.WriteAllText(fileName, sb.ToString()) - End Sub + ''' + ''' Esportazione statistiche attuali esecuzione + ''' + ''' + ''' + Private Sub btnExportStats_Click(sender As Object, e As EventArgs) Handles btnExportStats.Click + ' statistiche di sintesi + Dim sorted = From pair In ProcStats.ExeCumSum + Order By pair.Key + ' preparo il file export... + Dim fileName As String + Dim adesso As DateTime = DateTime.Now + fileName = Path.Combine("C:\Temp\", $"WDC_Stats_{adesso:yyyyMMdd-HHmmss}.csv") + Dim sb As StringBuilder = New StringBuilder + sb.AppendLine("Threads;Samples;ExeTime;OtherTime;FullTime") + For Each item In sorted + ' preparo la linea CSV... + sb.AppendLine($"{item.Key};{item.Value.NumRec};{item.Value.ExeTime / item.Value.NumRec:N2};{item.Value.OthTime / item.Value.NumRec:N2};{(item.Value.ExeTime + item.Value.OthTime) / item.Key:N2}") + Next + ' scrivo! + File.WriteAllText(fileName, sb.ToString()) + End Sub - Private Sub ProcMan_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing - ' forzo chiusura threads! - stopAllThreads() - End Sub + Private Sub ProcMan_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing + ' forzo chiusura threads! + stopAllThreads() + End Sub - Private Sub chkAutoRestart_CheckedChanged(sender As Object, e As EventArgs) Handles chkAutoRestart.CheckedChanged - CheckStartAutoRestart() - End Sub + Private Sub chkAutoRestart_CheckedChanged(sender As Object, e As EventArgs) Handles chkAutoRestart.CheckedChanged + CheckStartAutoRestart() + End Sub - Private Sub CheckStartAutoRestart() - TimerCheck.Enabled = chkAutoRestart.Checked - If chkAutoRestart.Checked Then - TimerCheck.Start() - Task.Delay(500) - startAllThreads() - Else - TimerCheck.Stop() - End If - End Sub + Private Sub CheckStartAutoRestart() + TimerCheck.Enabled = chkAutoRestart.Checked + If chkAutoRestart.Checked Then + TimerCheck.Start() + Task.Delay(500) + startAllThreads() + Else + TimerCheck.Stop() + End If + End Sub - Private Sub TimerCheck_Tick(sender As Object, e As EventArgs) Handles TimerCheck.Tick - restartAll() - End Sub + Private Sub TimerCheck_Tick(sender As Object, e As EventArgs) Handles TimerCheck.Tick + restartAll() + End Sub - Private Sub restartAll() - ' eseguo riavvio forzato ogni 30 sec! - stopAllThreads() - Task.Delay(500) - startAllThreads() - End Sub + Private Sub restartAll() + ' eseguo riavvio forzato ogni 30 sec! + stopAllThreads() + Task.Delay(500) + startAllThreads() + End Sub #End Region From caaa2c602a18d6bef9509773c65963021508a3a1 Mon Sep 17 00:00:00 2001 From: Emmanuele Sassi Date: Wed, 17 May 2023 09:53:58 +0200 Subject: [PATCH 2/3] =?UTF-8?q?-=20migliorie=20alla=20stabilit=C3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebDoorCreator.CamSrv/ProcMan.Designer.vb | 684 +++++++++++----------- WebDoorCreator.CamSrv/ProcMan.vb | 127 +++- 2 files changed, 468 insertions(+), 343 deletions(-) diff --git a/WebDoorCreator.CamSrv/ProcMan.Designer.vb b/WebDoorCreator.CamSrv/ProcMan.Designer.vb index a88f397..d64f025 100644 --- a/WebDoorCreator.CamSrv/ProcMan.Designer.vb +++ b/WebDoorCreator.CamSrv/ProcMan.Designer.vb @@ -22,343 +22,355 @@ Partial Class ProcMan 'Do not modify it using the code editor. _ 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() - Me.lblTestAlive = New System.Windows.Forms.Label() - Me.btnTestAlive = New System.Windows.Forms.Button() - Me.btnResetQueue = New System.Windows.Forms.Button() - Me.txtOut = New System.Windows.Forms.TextBox() - Me.btnQueueStatus = New System.Windows.Forms.Button() - Me.StartProcess = New System.Windows.Forms.Button() - Me.StopProcess = New System.Windows.Forms.Button() - Me.StatusStrip1 = New System.Windows.Forms.StatusStrip() - Me.tsProgBar = New System.Windows.Forms.ToolStripProgressBar() - Me.txtQueue = New System.Windows.Forms.TextBox() - 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.LISTThreadStatus = New System.Windows.Forms.ListView() - Me.chThread = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) - Me.chTime = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) - Me.chOther = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) - Me.GroupBox1 = New System.Windows.Forms.GroupBox() - Me.chkStatAggr = New System.Windows.Forms.CheckBox() - Me.btnExportStats = New System.Windows.Forms.Button() - Me.chkAutoRestart = New System.Windows.Forms.CheckBox() - Me.TimerCheck = New System.Windows.Forms.Timer(Me.components) - Me.ThreadCurrentStatusList = New System.Windows.Forms.ListView() - Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) - Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) - Me.StatusStrip1.SuspendLayout() - Me.GroupBox1.SuspendLayout() - Me.SuspendLayout() - ' - 'btnTestPing - ' - Me.btnTestPing.Location = New System.Drawing.Point(17, 16) - Me.btnTestPing.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.btnTestPing.Name = "btnTestPing" - Me.btnTestPing.Size = New System.Drawing.Size(100, 28) - Me.btnTestPing.TabIndex = 0 - Me.btnTestPing.Text = "Test Ping" - Me.btnTestPing.UseVisualStyleBackColor = True - ' - 'lblpingTest - ' - Me.lblpingTest.AutoSize = True - Me.lblpingTest.Location = New System.Drawing.Point(153, 22) - Me.lblpingTest.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) - Me.lblpingTest.Name = "lblpingTest" - Me.lblpingTest.Size = New System.Drawing.Size(28, 16) - Me.lblpingTest.TabIndex = 1 - Me.lblpingTest.Text = "???" - ' - 'lblTestAlive - ' - Me.lblTestAlive.AutoSize = True - Me.lblTestAlive.Location = New System.Drawing.Point(365, 22) - Me.lblTestAlive.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) - Me.lblTestAlive.Name = "lblTestAlive" - Me.lblTestAlive.Size = New System.Drawing.Size(28, 16) - Me.lblTestAlive.TabIndex = 3 - Me.lblTestAlive.Text = "???" - ' - 'btnTestAlive - ' - Me.btnTestAlive.Location = New System.Drawing.Point(229, 16) - Me.btnTestAlive.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.btnTestAlive.Name = "btnTestAlive" - Me.btnTestAlive.Size = New System.Drawing.Size(100, 28) - Me.btnTestAlive.TabIndex = 2 - Me.btnTestAlive.Text = "Test Alive" - Me.btnTestAlive.UseVisualStyleBackColor = True - ' - 'btnResetQueue - ' - Me.btnResetQueue.Location = New System.Drawing.Point(17, 201) - Me.btnResetQueue.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.btnResetQueue.Name = "btnResetQueue" - Me.btnResetQueue.Size = New System.Drawing.Size(100, 28) - Me.btnResetQueue.TabIndex = 6 - Me.btnResetQueue.Text = "Reset Q" - Me.btnResetQueue.UseVisualStyleBackColor = True - ' - 'txtOut - ' - Me.txtOut.BackColor = System.Drawing.SystemColors.ControlDarkDark - Me.txtOut.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.txtOut.ForeColor = System.Drawing.Color.Yellow - Me.txtOut.Location = New System.Drawing.Point(16, 240) - Me.txtOut.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.txtOut.MinimumSize = New System.Drawing.Size(79, 147) - Me.txtOut.Multiline = True - Me.txtOut.Name = "txtOut" - Me.txtOut.Size = New System.Drawing.Size(99, 173) - Me.txtOut.TabIndex = 7 - Me.txtOut.Text = "---" - ' - 'btnQueueStatus - ' - Me.btnQueueStatus.Location = New System.Drawing.Point(17, 79) - Me.btnQueueStatus.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.btnQueueStatus.Name = "btnQueueStatus" - Me.btnQueueStatus.Size = New System.Drawing.Size(100, 28) - Me.btnQueueStatus.TabIndex = 8 - Me.btnQueueStatus.Text = "Stato Queue" - Me.btnQueueStatus.UseVisualStyleBackColor = True - ' - 'StartProcess - ' - Me.StartProcess.Location = New System.Drawing.Point(17, 23) - Me.StartProcess.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.StartProcess.Name = "StartProcess" - Me.StartProcess.Size = New System.Drawing.Size(100, 28) - Me.StartProcess.TabIndex = 9 - Me.StartProcess.Text = "Start" - Me.StartProcess.UseVisualStyleBackColor = True - ' - 'StopProcess - ' - Me.StopProcess.Location = New System.Drawing.Point(325, 22) - Me.StopProcess.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.StopProcess.Name = "StopProcess" - Me.StopProcess.Size = New System.Drawing.Size(100, 28) - Me.StopProcess.TabIndex = 10 - Me.StopProcess.Text = "Stop" - Me.StopProcess.UseVisualStyleBackColor = True - ' - 'StatusStrip1 - ' - Me.StatusStrip1.ImageScalingSize = New System.Drawing.Size(20, 20) - Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tsProgBar}) - Me.StatusStrip1.Location = New System.Drawing.Point(0, 523) - Me.StatusStrip1.Name = "StatusStrip1" - Me.StatusStrip1.Padding = New System.Windows.Forms.Padding(1, 0, 19, 0) - Me.StatusStrip1.Size = New System.Drawing.Size(736, 25) - Me.StatusStrip1.TabIndex = 11 - Me.StatusStrip1.Text = "StatusStrip1" - ' - 'tsProgBar - ' - Me.tsProgBar.Name = "tsProgBar" - Me.tsProgBar.Size = New System.Drawing.Size(133, 17) - Me.tsProgBar.Step = 1 - ' - 'txtQueue - ' - Me.txtQueue.BackColor = System.Drawing.SystemColors.ControlDarkDark - Me.txtQueue.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!) - Me.txtQueue.ForeColor = System.Drawing.SystemColors.Window - Me.txtQueue.Location = New System.Drawing.Point(17, 114) - Me.txtQueue.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.txtQueue.Multiline = True - Me.txtQueue.Name = "txtQueue" - Me.txtQueue.Size = New System.Drawing.Size(99, 78) - Me.txtQueue.TabIndex = 12 - Me.txtQueue.Text = "Q Status:" - ' - 'Label1 - ' - Me.Label1.AutoSize = True - Me.Label1.Location = New System.Drawing.Point(132, 30) - Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) - Me.Label1.Name = "Label1" - Me.Label1.Size = New System.Drawing.Size(35, 16) - Me.Label1.TabIndex = 13 - Me.Label1.Text = "num:" - ' - 'txtNumThread - ' - Me.txtNumThread.Location = New System.Drawing.Point(171, 26) - Me.txtNumThread.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.txtNumThread.Name = "txtNumThread" - Me.txtNumThread.Size = New System.Drawing.Size(41, 22) - Me.txtNumThread.TabIndex = 14 - Me.txtNumThread.Text = "1" - Me.txtNumThread.TextAlign = System.Windows.Forms.HorizontalAlignment.Right - ' - 'lblRunning - ' - Me.lblRunning.AutoSize = True - Me.lblRunning.Location = New System.Drawing.Point(221, 30) - Me.lblRunning.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) - Me.lblRunning.MinimumSize = New System.Drawing.Size(100, 0) - Me.lblRunning.Name = "lblRunning" - Me.lblRunning.Size = New System.Drawing.Size(100, 16) - Me.lblRunning.TabIndex = 15 - Me.lblRunning.Text = "running: -" - Me.lblRunning.TextAlign = System.Drawing.ContentAlignment.MiddleCenter - ' - 'TimerUI - ' - Me.TimerUI.Interval = 300 - ' - 'TimerProgBar - ' - ' - 'LISTThreadStatus - ' - Me.LISTThreadStatus.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.chThread, Me.chTime, Me.chOther}) - Me.LISTThreadStatus.HideSelection = False - Me.LISTThreadStatus.Location = New System.Drawing.Point(17, 59) - Me.LISTThreadStatus.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.LISTThreadStatus.Name = "LISTThreadStatus" - Me.LISTThreadStatus.Size = New System.Drawing.Size(536, 173) - Me.LISTThreadStatus.TabIndex = 16 - Me.LISTThreadStatus.UseCompatibleStateImageBehavior = False - Me.LISTThreadStatus.View = System.Windows.Forms.View.Details - ' - 'chThread - ' - Me.chThread.Text = "Thread" - Me.chThread.Width = 100 - ' - 'chTime - ' - Me.chTime.Text = "Time" - Me.chTime.Width = 100 - ' - 'chOther - ' - Me.chOther.Text = "Other" - Me.chOther.Width = 100 - ' - 'GroupBox1 - ' - Me.GroupBox1.Controls.Add(Me.ThreadCurrentStatusList) - Me.GroupBox1.Controls.Add(Me.chkStatAggr) - Me.GroupBox1.Controls.Add(Me.LISTThreadStatus) - Me.GroupBox1.Controls.Add(Me.lblRunning) - Me.GroupBox1.Controls.Add(Me.txtNumThread) - Me.GroupBox1.Controls.Add(Me.StopProcess) - Me.GroupBox1.Controls.Add(Me.Label1) - Me.GroupBox1.Controls.Add(Me.StartProcess) - Me.GroupBox1.Location = New System.Drawing.Point(157, 79) - Me.GroupBox1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.GroupBox1.Name = "GroupBox1" - Me.GroupBox1.Padding = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.GroupBox1.Size = New System.Drawing.Size(563, 438) - Me.GroupBox1.TabIndex = 17 - Me.GroupBox1.TabStop = False - Me.GroupBox1.Text = "Threads" - ' - 'chkStatAggr - ' - Me.chkStatAggr.AutoSize = True - Me.chkStatAggr.Checked = True - Me.chkStatAggr.CheckState = System.Windows.Forms.CheckState.Checked - Me.chkStatAggr.Location = New System.Drawing.Point(435, 26) - Me.chkStatAggr.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.chkStatAggr.Name = "chkStatAggr" - Me.chkStatAggr.Size = New System.Drawing.Size(91, 20) - Me.chkStatAggr.TabIndex = 17 - Me.chkStatAggr.Text = "Aggr Stats" - Me.chkStatAggr.UseVisualStyleBackColor = True - ' - 'btnExportStats - ' - Me.btnExportStats.Location = New System.Drawing.Point(612, 16) - Me.btnExportStats.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.btnExportStats.Name = "btnExportStats" - Me.btnExportStats.Size = New System.Drawing.Size(100, 28) - Me.btnExportStats.TabIndex = 18 - Me.btnExportStats.Text = "Export Stats" - Me.btnExportStats.UseVisualStyleBackColor = True - ' - 'chkAutoRestart - ' - Me.chkAutoRestart.AutoSize = True - Me.chkAutoRestart.Checked = True - Me.chkAutoRestart.CheckState = System.Windows.Forms.CheckState.Checked - Me.chkAutoRestart.Location = New System.Drawing.Point(465, 21) - Me.chkAutoRestart.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.chkAutoRestart.Name = "chkAutoRestart" - Me.chkAutoRestart.Size = New System.Drawing.Size(99, 20) - Me.chkAutoRestart.TabIndex = 19 - Me.chkAutoRestart.Text = "AutoRestart" - Me.chkAutoRestart.UseVisualStyleBackColor = True - ' - 'TimerCheck - ' - Me.TimerCheck.Interval = 30000 - ' - 'ThreadCurrentStatusList - ' - Me.ThreadCurrentStatusList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2}) - Me.ThreadCurrentStatusList.HideSelection = False - Me.ThreadCurrentStatusList.Location = New System.Drawing.Point(17, 257) - Me.ThreadCurrentStatusList.Margin = New System.Windows.Forms.Padding(4) - Me.ThreadCurrentStatusList.Name = "ThreadCurrentStatusList" - Me.ThreadCurrentStatusList.Size = New System.Drawing.Size(536, 173) - Me.ThreadCurrentStatusList.TabIndex = 18 - Me.ThreadCurrentStatusList.UseCompatibleStateImageBehavior = False - Me.ThreadCurrentStatusList.View = System.Windows.Forms.View.Details - ' - 'ColumnHeader1 - ' - Me.ColumnHeader1.Text = "Thread" - Me.ColumnHeader1.Width = 100 - ' - 'ColumnHeader2 - ' - Me.ColumnHeader2.Text = "Status" - Me.ColumnHeader2.Width = 100 - ' - 'ProcMan - ' - Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!) - Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(736, 548) - Me.Controls.Add(Me.chkAutoRestart) - Me.Controls.Add(Me.btnExportStats) - Me.Controls.Add(Me.GroupBox1) - Me.Controls.Add(Me.txtQueue) - Me.Controls.Add(Me.StatusStrip1) - Me.Controls.Add(Me.btnQueueStatus) - Me.Controls.Add(Me.txtOut) - Me.Controls.Add(Me.btnResetQueue) - Me.Controls.Add(Me.lblTestAlive) - Me.Controls.Add(Me.btnTestAlive) - Me.Controls.Add(Me.lblpingTest) - Me.Controls.Add(Me.btnTestPing) - Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) - Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) - Me.Name = "ProcMan" - Me.Text = "MainForm" - Me.StatusStrip1.ResumeLayout(False) - Me.StatusStrip1.PerformLayout() - Me.GroupBox1.ResumeLayout(False) - Me.GroupBox1.PerformLayout() - Me.ResumeLayout(False) - Me.PerformLayout() + 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() + Me.lblTestAlive = New System.Windows.Forms.Label() + Me.btnTestAlive = New System.Windows.Forms.Button() + Me.btnResetQueue = New System.Windows.Forms.Button() + Me.txtOut = New System.Windows.Forms.TextBox() + Me.btnQueueStatus = New System.Windows.Forms.Button() + Me.StartProcess = New System.Windows.Forms.Button() + Me.StopProcess = New System.Windows.Forms.Button() + Me.StatusStrip1 = New System.Windows.Forms.StatusStrip() + Me.tsProgBar = New System.Windows.Forms.ToolStripProgressBar() + Me.txtQueue = New System.Windows.Forms.TextBox() + 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.LISTThreadStatus = New System.Windows.Forms.ListView() + Me.chThread = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.chTime = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.chOther = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.GroupBox1 = New System.Windows.Forms.GroupBox() + Me.ThreadCurrentStatusList = New System.Windows.Forms.ListView() + Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.chkStatAggr = New System.Windows.Forms.CheckBox() + Me.btnExportStats = New System.Windows.Forms.Button() + Me.chkAutoRestart = New System.Windows.Forms.CheckBox() + Me.TimerCheck = New System.Windows.Forms.Timer(Me.components) + Me.ColumnHeader3 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.ColumnHeader4 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) + Me.StatusStrip1.SuspendLayout() + Me.GroupBox1.SuspendLayout() + Me.SuspendLayout() + ' + 'btnTestPing + ' + Me.btnTestPing.Location = New System.Drawing.Point(17, 16) + Me.btnTestPing.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.btnTestPing.Name = "btnTestPing" + Me.btnTestPing.Size = New System.Drawing.Size(100, 28) + Me.btnTestPing.TabIndex = 0 + Me.btnTestPing.Text = "Test Ping" + Me.btnTestPing.UseVisualStyleBackColor = True + ' + 'lblpingTest + ' + Me.lblpingTest.AutoSize = True + Me.lblpingTest.Location = New System.Drawing.Point(153, 22) + Me.lblpingTest.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) + Me.lblpingTest.Name = "lblpingTest" + Me.lblpingTest.Size = New System.Drawing.Size(28, 16) + Me.lblpingTest.TabIndex = 1 + Me.lblpingTest.Text = "???" + ' + 'lblTestAlive + ' + Me.lblTestAlive.AutoSize = True + Me.lblTestAlive.Location = New System.Drawing.Point(365, 22) + Me.lblTestAlive.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) + Me.lblTestAlive.Name = "lblTestAlive" + Me.lblTestAlive.Size = New System.Drawing.Size(28, 16) + Me.lblTestAlive.TabIndex = 3 + Me.lblTestAlive.Text = "???" + ' + 'btnTestAlive + ' + Me.btnTestAlive.Location = New System.Drawing.Point(229, 16) + Me.btnTestAlive.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.btnTestAlive.Name = "btnTestAlive" + Me.btnTestAlive.Size = New System.Drawing.Size(100, 28) + Me.btnTestAlive.TabIndex = 2 + Me.btnTestAlive.Text = "Test Alive" + Me.btnTestAlive.UseVisualStyleBackColor = True + ' + 'btnResetQueue + ' + Me.btnResetQueue.Location = New System.Drawing.Point(17, 201) + Me.btnResetQueue.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.btnResetQueue.Name = "btnResetQueue" + Me.btnResetQueue.Size = New System.Drawing.Size(100, 28) + Me.btnResetQueue.TabIndex = 6 + Me.btnResetQueue.Text = "Reset Q" + Me.btnResetQueue.UseVisualStyleBackColor = True + ' + 'txtOut + ' + Me.txtOut.BackColor = System.Drawing.SystemColors.ControlDarkDark + Me.txtOut.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.txtOut.ForeColor = System.Drawing.Color.Yellow + Me.txtOut.Location = New System.Drawing.Point(16, 240) + Me.txtOut.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.txtOut.MinimumSize = New System.Drawing.Size(79, 147) + Me.txtOut.Multiline = True + Me.txtOut.Name = "txtOut" + Me.txtOut.Size = New System.Drawing.Size(99, 173) + Me.txtOut.TabIndex = 7 + Me.txtOut.Text = "---" + ' + 'btnQueueStatus + ' + Me.btnQueueStatus.Location = New System.Drawing.Point(17, 79) + Me.btnQueueStatus.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.btnQueueStatus.Name = "btnQueueStatus" + Me.btnQueueStatus.Size = New System.Drawing.Size(100, 28) + Me.btnQueueStatus.TabIndex = 8 + Me.btnQueueStatus.Text = "Stato Queue" + Me.btnQueueStatus.UseVisualStyleBackColor = True + ' + 'StartProcess + ' + Me.StartProcess.Location = New System.Drawing.Point(17, 23) + Me.StartProcess.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.StartProcess.Name = "StartProcess" + Me.StartProcess.Size = New System.Drawing.Size(100, 28) + Me.StartProcess.TabIndex = 9 + Me.StartProcess.Text = "Start" + Me.StartProcess.UseVisualStyleBackColor = True + ' + 'StopProcess + ' + Me.StopProcess.Location = New System.Drawing.Point(325, 22) + Me.StopProcess.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.StopProcess.Name = "StopProcess" + Me.StopProcess.Size = New System.Drawing.Size(100, 28) + Me.StopProcess.TabIndex = 10 + Me.StopProcess.Text = "Stop" + Me.StopProcess.UseVisualStyleBackColor = True + ' + 'StatusStrip1 + ' + Me.StatusStrip1.ImageScalingSize = New System.Drawing.Size(20, 20) + Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tsProgBar}) + Me.StatusStrip1.Location = New System.Drawing.Point(0, 526) + Me.StatusStrip1.Name = "StatusStrip1" + Me.StatusStrip1.Padding = New System.Windows.Forms.Padding(1, 0, 19, 0) + Me.StatusStrip1.Size = New System.Drawing.Size(736, 22) + Me.StatusStrip1.TabIndex = 11 + Me.StatusStrip1.Text = "StatusStrip1" + ' + 'tsProgBar + ' + Me.tsProgBar.Name = "tsProgBar" + Me.tsProgBar.Size = New System.Drawing.Size(133, 14) + Me.tsProgBar.Step = 1 + ' + 'txtQueue + ' + Me.txtQueue.BackColor = System.Drawing.SystemColors.ControlDarkDark + Me.txtQueue.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!) + Me.txtQueue.ForeColor = System.Drawing.SystemColors.Window + Me.txtQueue.Location = New System.Drawing.Point(17, 114) + Me.txtQueue.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.txtQueue.Multiline = True + Me.txtQueue.Name = "txtQueue" + Me.txtQueue.Size = New System.Drawing.Size(99, 78) + Me.txtQueue.TabIndex = 12 + Me.txtQueue.Text = "Q Status:" + ' + 'Label1 + ' + Me.Label1.AutoSize = True + Me.Label1.Location = New System.Drawing.Point(132, 30) + Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) + Me.Label1.Name = "Label1" + Me.Label1.Size = New System.Drawing.Size(35, 16) + Me.Label1.TabIndex = 13 + Me.Label1.Text = "num:" + ' + 'txtNumThread + ' + Me.txtNumThread.Location = New System.Drawing.Point(171, 26) + Me.txtNumThread.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.txtNumThread.Name = "txtNumThread" + Me.txtNumThread.Size = New System.Drawing.Size(41, 22) + Me.txtNumThread.TabIndex = 14 + Me.txtNumThread.Text = "1" + Me.txtNumThread.TextAlign = System.Windows.Forms.HorizontalAlignment.Right + ' + 'lblRunning + ' + Me.lblRunning.AutoSize = True + Me.lblRunning.Location = New System.Drawing.Point(221, 30) + Me.lblRunning.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) + Me.lblRunning.MinimumSize = New System.Drawing.Size(100, 0) + Me.lblRunning.Name = "lblRunning" + Me.lblRunning.Size = New System.Drawing.Size(100, 16) + Me.lblRunning.TabIndex = 15 + Me.lblRunning.Text = "running: -" + Me.lblRunning.TextAlign = System.Drawing.ContentAlignment.MiddleCenter + ' + 'TimerUI + ' + Me.TimerUI.Interval = 800 + ' + 'TimerProgBar + ' + ' + 'LISTThreadStatus + ' + Me.LISTThreadStatus.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.chThread, Me.chTime, Me.chOther}) + Me.LISTThreadStatus.HideSelection = False + Me.LISTThreadStatus.Location = New System.Drawing.Point(17, 59) + Me.LISTThreadStatus.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.LISTThreadStatus.Name = "LISTThreadStatus" + Me.LISTThreadStatus.Size = New System.Drawing.Size(536, 173) + Me.LISTThreadStatus.TabIndex = 16 + Me.LISTThreadStatus.UseCompatibleStateImageBehavior = False + Me.LISTThreadStatus.View = System.Windows.Forms.View.Details + ' + 'chThread + ' + Me.chThread.Text = "Thread" + Me.chThread.Width = 100 + ' + 'chTime + ' + Me.chTime.Text = "Time" + Me.chTime.Width = 100 + ' + 'chOther + ' + Me.chOther.Text = "Other" + Me.chOther.Width = 100 + ' + 'GroupBox1 + ' + Me.GroupBox1.Controls.Add(Me.ThreadCurrentStatusList) + Me.GroupBox1.Controls.Add(Me.chkStatAggr) + Me.GroupBox1.Controls.Add(Me.LISTThreadStatus) + Me.GroupBox1.Controls.Add(Me.lblRunning) + Me.GroupBox1.Controls.Add(Me.txtNumThread) + Me.GroupBox1.Controls.Add(Me.StopProcess) + Me.GroupBox1.Controls.Add(Me.Label1) + Me.GroupBox1.Controls.Add(Me.StartProcess) + Me.GroupBox1.Location = New System.Drawing.Point(157, 79) + Me.GroupBox1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.GroupBox1.Name = "GroupBox1" + Me.GroupBox1.Padding = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.GroupBox1.Size = New System.Drawing.Size(563, 438) + Me.GroupBox1.TabIndex = 17 + Me.GroupBox1.TabStop = False + Me.GroupBox1.Text = "Threads" + ' + 'ThreadCurrentStatusList + ' + Me.ThreadCurrentStatusList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader4, Me.ColumnHeader3}) + Me.ThreadCurrentStatusList.HideSelection = False + Me.ThreadCurrentStatusList.Location = New System.Drawing.Point(17, 257) + Me.ThreadCurrentStatusList.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.ThreadCurrentStatusList.Name = "ThreadCurrentStatusList" + Me.ThreadCurrentStatusList.Size = New System.Drawing.Size(536, 173) + Me.ThreadCurrentStatusList.TabIndex = 18 + Me.ThreadCurrentStatusList.UseCompatibleStateImageBehavior = False + Me.ThreadCurrentStatusList.View = System.Windows.Forms.View.Details + ' + 'ColumnHeader1 + ' + Me.ColumnHeader1.Text = "Thread" + Me.ColumnHeader1.Width = 100 + ' + 'ColumnHeader2 + ' + Me.ColumnHeader2.Text = "Thread Status" + Me.ColumnHeader2.Width = 100 + ' + 'chkStatAggr + ' + Me.chkStatAggr.AutoSize = True + Me.chkStatAggr.Checked = True + Me.chkStatAggr.CheckState = System.Windows.Forms.CheckState.Checked + Me.chkStatAggr.Location = New System.Drawing.Point(435, 26) + Me.chkStatAggr.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.chkStatAggr.Name = "chkStatAggr" + Me.chkStatAggr.Size = New System.Drawing.Size(91, 20) + Me.chkStatAggr.TabIndex = 17 + Me.chkStatAggr.Text = "Aggr Stats" + Me.chkStatAggr.UseVisualStyleBackColor = True + ' + 'btnExportStats + ' + Me.btnExportStats.Location = New System.Drawing.Point(612, 16) + Me.btnExportStats.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.btnExportStats.Name = "btnExportStats" + Me.btnExportStats.Size = New System.Drawing.Size(100, 28) + Me.btnExportStats.TabIndex = 18 + Me.btnExportStats.Text = "Export Stats" + Me.btnExportStats.UseVisualStyleBackColor = True + ' + 'chkAutoRestart + ' + Me.chkAutoRestart.AutoSize = True + Me.chkAutoRestart.Location = New System.Drawing.Point(465, 21) + Me.chkAutoRestart.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.chkAutoRestart.Name = "chkAutoRestart" + Me.chkAutoRestart.Size = New System.Drawing.Size(99, 20) + Me.chkAutoRestart.TabIndex = 19 + Me.chkAutoRestart.Text = "AutoRestart" + Me.chkAutoRestart.UseVisualStyleBackColor = True + ' + 'TimerCheck + ' + Me.TimerCheck.Interval = 30000 + ' + 'ColumnHeader3 + ' + Me.ColumnHeader3.DisplayIndex = 2 + Me.ColumnHeader3.Text = "Process Status" + Me.ColumnHeader3.Width = 100 + ' + 'ColumnHeader4 + ' + Me.ColumnHeader4.DisplayIndex = 3 + Me.ColumnHeader4.Text = "Thread Phase" + Me.ColumnHeader4.Width = 100 + ' + 'ProcMan + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(736, 548) + Me.Controls.Add(Me.chkAutoRestart) + Me.Controls.Add(Me.btnExportStats) + Me.Controls.Add(Me.GroupBox1) + Me.Controls.Add(Me.txtQueue) + Me.Controls.Add(Me.StatusStrip1) + Me.Controls.Add(Me.btnQueueStatus) + Me.Controls.Add(Me.txtOut) + Me.Controls.Add(Me.btnResetQueue) + Me.Controls.Add(Me.lblTestAlive) + Me.Controls.Add(Me.btnTestAlive) + Me.Controls.Add(Me.lblpingTest) + Me.Controls.Add(Me.btnTestPing) + Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) + Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) + Me.Name = "ProcMan" + Me.Text = "MainForm" + Me.StatusStrip1.ResumeLayout(False) + Me.StatusStrip1.PerformLayout() + Me.GroupBox1.ResumeLayout(False) + Me.GroupBox1.PerformLayout() + Me.ResumeLayout(False) + Me.PerformLayout() - End Sub + End Sub - Friend WithEvents btnTestPing As Button + Friend WithEvents btnTestPing As Button Friend WithEvents lblpingTest As Label Friend WithEvents lblTestAlive As Label Friend WithEvents btnTestAlive As Button @@ -387,4 +399,6 @@ Partial Class ProcMan Friend WithEvents ThreadCurrentStatusList As ListView Friend WithEvents ColumnHeader1 As ColumnHeader Friend WithEvents ColumnHeader2 As ColumnHeader + Friend WithEvents ColumnHeader3 As ColumnHeader + Friend WithEvents ColumnHeader4 As ColumnHeader End Class diff --git a/WebDoorCreator.CamSrv/ProcMan.vb b/WebDoorCreator.CamSrv/ProcMan.vb index d24ff2e..cdd3c5e 100644 --- a/WebDoorCreator.CamSrv/ProcMan.vb +++ b/WebDoorCreator.CamSrv/ProcMan.vb @@ -62,7 +62,42 @@ Public Class ProcMan Dim ThreadList As Thread() + Dim ThreadDataList As ThreadData() + #End Region + Enum ThreadOperations As Integer + WaitingData = 1 + FoundRequest = 2 + WritingDdf = 3 + ProcessingDdf = 4 + ReadingSvg = 5 + SendResult = 6 + Closed = 10 + End Enum + + Private Class ThreadData + + Private m_ThreadOperation As ThreadOperations + Public ReadOnly Property ThreadOperation As ThreadOperations + Get + Return m_ThreadOperation + End Get + End Property + Friend Sub SetThreadOperation(value As ThreadOperations) + m_ThreadOperation = value + End Sub + + Private m_Process As Process + Public ReadOnly Property Process As Process + Get + Return m_Process + End Get + End Property + Friend Sub SetProcess(value As Process) + m_Process = value + End Sub + + End Class #Region "Private Methods" @@ -74,7 +109,20 @@ Public Class ProcMan If Not IsNothing(ThreadList) Then For ThreadIndex = 0 To ThreadList.Count - 1 - ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, If(Not IsNothing(ThreadList(ThreadIndex)), ThreadList(ThreadIndex).ThreadState.ToString(), "nothing")})) + If Not IsNothing(ThreadList(ThreadIndex)) Then + Dim ThreadProcessState As String = "Nothing" + 'If Not IsNothing(ThreadDataList(ThreadIndex)) AndAlso Not IsNothing(ThreadDataList(ThreadIndex).Process) AndAlso + 'Not IsNothing(ThreadDataList(ThreadIndex).Process.HasExited) Then + ' ThreadProcessState = ThreadDataList(ThreadIndex).Process.HasExited + 'End If + ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, + ThreadList(ThreadIndex).ThreadState.ToString(), + ThreadProcessState, + ThreadDataList(ThreadIndex).ThreadOperation.ToString()})) + Else + ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, + "nothing"})) + End If Next End If ThreadCurrentStatusList.EndUpdate() @@ -174,9 +222,11 @@ Public Class ProcMan If bOk AndAlso (IsNothing(ThreadList) OrElse ThreadList.Count = 0 OrElse IsNothing(ThreadList(0))) Then ThreadList = New Thread(m_MaxCamInstances - 1) {} + ThreadDataList = New ThreadData(m_MaxCamInstances - 1) {} For nThreadIndex = 0 To m_MaxCamInstances - 1 + Dim ThreadId As Integer = nThreadIndex ThreadList(nThreadIndex) = New Thread(Sub() - ThreadFunction() + ThreadFunction(ThreadId) End Sub) ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA) ' avvio thread di gestione della macchina che avvia la connessione @@ -184,6 +234,17 @@ Public Class ProcMan Thread.Sleep(10) Next End If + ' se qualche processo in stop, lo faccio ripartire + For ThreadIndex = 0 To ThreadList.Count - 1 + Dim Thread = ThreadList(ThreadIndex) + If Thread.ThreadState = ThreadState.Stopped Then + Thread.Abort() + Dim ThreadId As Integer = ThreadIndex + Thread = New Thread(Sub() + ThreadFunction(ThreadId) + End Sub) + End If + Next If n30SecCounter <= 30 Then n30SecCounter += 1 Else @@ -545,8 +606,9 @@ Public Class ProcMan Return numCount End Function - Private Sub ThreadFunction() - + Private Sub ThreadFunction(ThreadIndex As Integer) + Dim MyThreadData As New ThreadData + ThreadDataList(ThreadIndex) = MyThreadData Dim sExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe" Dim sCurrDdfDir As String = "c:\EgtData\WebDoor\Ddf" Dim stopWatch As New Stopwatch() @@ -554,12 +616,12 @@ Public Class ProcMan Dim lOtherTime As Long = 0 While Not m_bStopProcess - + MyThreadData.SetThreadOperation(ThreadOperations.WaitingData) ' se c'e' qualcosa da processare If currWDC.numTask2proc > 0 Then - Dim LastRequest As Dictionary(Of String, String) = currWDC.queueList(1) If LastRequest.Count > 0 Then + MyThreadData.SetThreadOperation(ThreadOperations.FoundRequest) Dim Item As KeyValuePair(Of String, String) = LastRequest.First() Dim bOk As Boolean = Not IsNothing(Item) If bOk Then @@ -577,6 +639,7 @@ Public Class ProcMan End If ' scrivo ddf + MyThreadData.SetThreadOperation(ThreadOperations.WritingDdf) Dim sDdfPath As String = sCurrDdfDir & "\" & Item.Key & ".ddf" Try File.WriteAllText(sDdfPath, Item.Value) @@ -585,9 +648,11 @@ Public Class ProcMan End Try If bOk Then + MyThreadData.SetThreadOperation(ThreadOperations.ProcessingDdf) ' eseguo calcolo - Dim Proc As New Process() + Dim Proc As Process = New Process() + MyThreadData.SetProcess(Proc) Proc.StartInfo.FileName = sExePath Proc.StartInfo.Arguments = """C:\EgtData\WebDoor\Main.lua""" & " """ & sDdfPath & """" Proc.StartInfo.UseShellExecute = False @@ -597,6 +662,7 @@ Public Class ProcMan While Not Proc.HasExited Thread.Sleep(1) End While + MyThreadData.SetProcess(Nothing) ' salvo exe time... stopWatch.Stop() lExeTime = stopWatch.ElapsedMilliseconds @@ -604,6 +670,7 @@ Public Class ProcMan Dim procResults As New List(Of CalcResultDTO) Dim currRes As New CalcResultDTO Dim fContent As String = "" + MyThreadData.SetThreadOperation(ThreadOperations.ReadingSvg) ' verifico esistenza file svg e lo carico bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "svg"), fContent) ' invio risposta @@ -616,6 +683,7 @@ Public Class ProcMan bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "txt"), fContent) currRes.ErrorMsg = fContent End If + MyThreadData.SetThreadOperation(ThreadOperations.SendResult) procResults.Add(currRes) Dim respPut As String = currWDC.SendProcResults(procResults) @@ -624,14 +692,57 @@ Public Class ProcMan lOtherTime = stopWatch.ElapsedMilliseconds ' aggiorno thread display... UpdateThreadList(Item.Key, lExeTime, lOtherTime) + ' cambio nomi file generati in old + Dim OldSvg As String = Path.ChangeExtension(sDdfPath, "svg") + Dim NewSvg As String = Path.GetDirectoryName(sDdfPath) & "\" & Path.GetFileNameWithoutExtension(sDdfPath) & "_old.svg" + Try + File.Delete(NewSvg) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "txt")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "log")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "nge")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "ddf")) + Catch ex As Exception + End Try + Try + File.Move(OldSvg, NewSvg) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "txt"), Path.ChangeExtension(NewSvg, "txt")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "log"), Path.ChangeExtension(NewSvg, "log")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "nge"), Path.ChangeExtension(NewSvg, "nge")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "ddf"), Path.ChangeExtension(NewSvg, "ddf")) + Catch ex As Exception + End Try End If stopWatch.Stop() - End If End If End If End If End While + MyThreadData.SetThreadOperation(ThreadOperations.Closed) End Sub From 813a1733dd7bd284cf8bab97e8ab005b68aacd95 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 17 May 2023 10:48:30 +0200 Subject: [PATCH 3/3] Fix processo startup threads --- WebDoorCreator.CamSrv/ProcMan.vb | 1076 +++++++++++++++--------------- 1 file changed, 538 insertions(+), 538 deletions(-) diff --git a/WebDoorCreator.CamSrv/ProcMan.vb b/WebDoorCreator.CamSrv/ProcMan.vb index cdd3c5e..afb5512 100644 --- a/WebDoorCreator.CamSrv/ProcMan.vb +++ b/WebDoorCreator.CamSrv/ProcMan.vb @@ -8,334 +8,328 @@ Public Class ProcMan #Region "Public Constructors" - Public Sub New() + Public Sub New() - ' This call is required by the designer. - InitializeComponent() + ' This call is required by the designer. + InitializeComponent() - ' Add any initialization after the InitializeComponent() call. - synchronizationContext = SynchronizationContext.Current - ' preparo lista thread... - 'Begin the update - LISTThreadStatus.BeginUpdate() - 'clear the List - LISTThreadStatus.Items.Clear() - 'Add init - LISTThreadStatus.Items.Add(New ListViewItem(New String() {"init", "waiting", "-"})) - 'End the update - LISTThreadStatus.EndUpdate() - StartUiThread() - startAllThreads() - CheckStartAutoRestart() + ' Add any initialization after the InitializeComponent() call. + synchronizationContext = SynchronizationContext.Current + m_bStopProcess = True + SetMaxCamInstances(1) + StartUiThread() + ' preparo lista thread... + LISTThreadStatus.BeginUpdate() + LISTThreadStatus.Items.Clear() + LISTThreadStatus.Items.Add(New ListViewItem(New String() {"init", "waiting", "-"})) + LISTThreadStatus.EndUpdate() - End Sub + ' verifico SE avviare + If chkAutoRestart.Checked Then + startAllThreads() + End If + CheckStartAutoRestart() + + End Sub #End Region #Region "Private Fields" - Private ReadOnly synchronizationContext As SynchronizationContext + 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" + ' 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 baseUrl As String = "https://iis01.egalware.com/WDC/SRV/" - Dim codPost As String = "WRK001" + Dim codPost As String = "WRK001" - ' nome macchina calcolo - Dim currWDC As WDC = New WDC(baseIp, baseUrl, codPost) + ' nome macchina calcolo + Dim currWDC As WDC = New WDC(baseIp, baseUrl, codPost) - Dim idxSim As Integer = 0 + Dim idxSim As Integer = 0 - Dim m_bExecutionThreadStoped As Boolean = False + Dim m_bExecutionThreadStoped As Boolean = False - Dim m_bStopProcess As Boolean = False + Dim m_bStopProcess As Boolean = False - Dim m_ExecutionThread As Thread + Dim m_ExecutionThread As Thread - 'Private m_MaxCamInstances As Integer = 8 - Private m_MaxCamInstances As Integer = 1 + 'Private m_MaxCamInstances As Integer = 8 + Private m_MaxCamInstances As Integer = 1 - Dim risultatoPing As PingReply = Nothing + Dim risultatoPing As PingReply = Nothing - Dim ThreadList As Thread() + Dim ThreadList As Thread() - Dim ThreadDataList As ThreadData() + Dim ThreadDataList As ThreadData() #End Region - Enum ThreadOperations As Integer - WaitingData = 1 - FoundRequest = 2 - WritingDdf = 3 - ProcessingDdf = 4 - ReadingSvg = 5 - SendResult = 6 - Closed = 10 - End Enum + Enum ThreadOperations As Integer + WaitingData = 1 + FoundRequest = 2 + WritingDdf = 3 + ProcessingDdf = 4 + ReadingSvg = 5 + SendResult = 6 + Closed = 10 + End Enum - Private Class ThreadData + Private Class ThreadData - Private m_ThreadOperation As ThreadOperations - Public ReadOnly Property ThreadOperation As ThreadOperations - Get - Return m_ThreadOperation - End Get - End Property - Friend Sub SetThreadOperation(value As ThreadOperations) - m_ThreadOperation = value - End Sub + Private m_ThreadOperation As ThreadOperations + Public ReadOnly Property ThreadOperation As ThreadOperations + Get + Return m_ThreadOperation + End Get + End Property + Friend Sub SetThreadOperation(value As ThreadOperations) + m_ThreadOperation = value + End Sub - Private m_Process As Process - Public ReadOnly Property Process As Process - Get - Return m_Process - End Get - End Property - Friend Sub SetProcess(value As Process) - m_Process = value - End Sub + Private m_Process As Process + Public ReadOnly Property Process As Process + Get + Return m_Process + End Get + End Property + Friend Sub SetProcess(value As Process) + m_Process = value + End Sub - End Class + End Class #Region "Private Methods" - Private Sub UpdateThreadCurrentStatus() - synchronizationContext.Post(New SendOrPostCallback( + Private Sub UpdateThreadCurrentStatus() + synchronizationContext.Post(New SendOrPostCallback( Sub(o) - ThreadCurrentStatusList.BeginUpdate() - ThreadCurrentStatusList.Items.Clear() + ThreadCurrentStatusList.BeginUpdate() + ThreadCurrentStatusList.Items.Clear() - If Not IsNothing(ThreadList) Then - For ThreadIndex = 0 To ThreadList.Count - 1 - If Not IsNothing(ThreadList(ThreadIndex)) Then - Dim ThreadProcessState As String = "Nothing" - 'If Not IsNothing(ThreadDataList(ThreadIndex)) AndAlso Not IsNothing(ThreadDataList(ThreadIndex).Process) AndAlso - 'Not IsNothing(ThreadDataList(ThreadIndex).Process.HasExited) Then - ' ThreadProcessState = ThreadDataList(ThreadIndex).Process.HasExited - 'End If - ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, + If Not IsNothing(ThreadList) Then + For ThreadIndex = 0 To ThreadList.Count - 1 + If Not IsNothing(ThreadList(ThreadIndex)) Then + Dim ThreadProcessState As String = "Nothing" + 'If Not IsNothing(ThreadDataList(ThreadIndex)) AndAlso Not IsNothing(ThreadDataList(ThreadIndex).Process) AndAlso + 'Not IsNothing(ThreadDataList(ThreadIndex).Process.HasExited) Then + ' ThreadProcessState = ThreadDataList(ThreadIndex).Process.HasExited + 'End If + ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, ThreadList(ThreadIndex).ThreadState.ToString(), ThreadProcessState, ThreadDataList(ThreadIndex).ThreadOperation.ToString()})) - Else - ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, + Else + ThreadCurrentStatusList.Items.Add(New ListViewItem(New String() {ThreadIndex, "nothing"})) - End If - Next - End If - ThreadCurrentStatusList.EndUpdate() + End If + Next + End If + ThreadCurrentStatusList.EndUpdate() End Sub), "") - End Sub + End Sub - Private Sub btnQueueStatus_Click(sender As Object, e As EventArgs) Handles btnQueueStatus.Click - DisplayQueueStatus() - End Sub + Private Sub btnQueueStatus_Click(sender As Object, e As EventArgs) Handles btnQueueStatus.Click + DisplayQueueStatus() + End Sub - Private Sub btnResetQueue_Click(sender As Object, e As EventArgs) Handles btnResetQueue.Click - currWDC.ResetQueue() - txtOut.Text = "Queue Resetted!" - End Sub + Private Sub btnResetQueue_Click(sender As Object, e As EventArgs) Handles btnResetQueue.Click + currWDC.ResetQueue() + txtOut.Text = "Queue Resetted!" + End Sub - Private Sub btnTestAlive_Click(sender As Object, e As EventArgs) Handles btnTestAlive.Click - Dim answ As String = "" - If (currWDC.testAlive) Then - lblTestAlive.Text = "Server Alive!!!" - Else - lblTestAlive.Text = "Alive test failed!" - End If - End Sub + Private Sub btnTestAlive_Click(sender As Object, e As EventArgs) Handles btnTestAlive.Click + Dim answ As String = "" + If (currWDC.testAlive) Then + lblTestAlive.Text = "Server Alive!!!" + Else + lblTestAlive.Text = "Alive test failed!" + End If + End Sub - Private Sub btnTestPing_Click(sender As Object, e As EventArgs) Handles btnTestPing.Click - ' chiamo test ping... - risultatoPing = currWDC.testPing - lblpingTest.Text = risultatoPing.Status.ToString() - End Sub + Private Sub btnTestPing_Click(sender As Object, e As EventArgs) Handles btnTestPing.Click + ' chiamo test ping... + risultatoPing = currWDC.testPing + lblpingTest.Text = risultatoPing.Status.ToString() + End Sub - Private Sub DisplayQueueStatus() - Dim queueStatus As New Dictionary(Of String, Long) - queueStatus = currWDC.queueStatus - Dim sb As StringBuilder - sb = New StringBuilder - For Each item As KeyValuePair(Of String, Long) In queueStatus - sb.AppendLine($"{item.Key}: {item.Value}") - Next - sb.AppendLine() - txtQueue.Text = sb.ToString() - txtQueue.Invalidate() - End Sub + Private Sub DisplayQueueStatus() + Dim queueStatus As New Dictionary(Of String, Long) + queueStatus = currWDC.queueStatus + Dim sb As StringBuilder + sb = New StringBuilder + For Each item As KeyValuePair(Of String, Long) In queueStatus + sb.AppendLine($"{item.Key}: {item.Value}") + Next + sb.AppendLine() + txtQueue.Text = sb.ToString() + txtQueue.Invalidate() + End Sub - Private Sub ExecutionProcess() - ' recupero Id dei DDF - Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf" - Dim sCurrDdfDir As String = "" - Dim nDdfId As Integer = 1 + Private Sub ExecutionProcess() + ' recupero Id dei DDF + Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf" + Dim sCurrDdfDir As String = "" + Dim nDdfId As Integer = 1 - Dim bStopMainProcess As Boolean = False - Dim n30SecCounter As Integer = 0 - While Not bStopMainProcess - bStopMainProcess = m_bStopProcess - Dim bOk As Boolean = False - While Not bOk - ' ogni 30 secondi - If n30SecCounter = 30 OrElse n30SecCounter = 0 Then - ' verifica connessione - Dim risultatoPing As PingReply = currWDC.testPing - bOk = risultatoPing.Status = IPStatus.Success - If bOk Then - bOk = currWDC.testAlive - End If - Else - bOk = True + Dim bStopMainProcess As Boolean = False + Dim n30SecCounter As Integer = 0 + While Not bStopMainProcess + bStopMainProcess = m_bStopProcess + Dim bOk As Boolean = False + While Not bOk + ' ogni 30 secondi + If n30SecCounter = 30 OrElse n30SecCounter = 0 Then + ' verifica connessione + Dim risultatoPing As PingReply = currWDC.testPing + bOk = risultatoPing.Status = IPStatus.Success + If bOk Then + bOk = currWDC.testAlive + End If + Else + bOk = True + End If + ' se connessione non ok o processo fermato, fermo i thread + If Not bOk OrElse bStopMainProcess Then + If Not IsNothing(ThreadList) AndAlso ThreadList.Count > 0 AndAlso Not IsNothing(ThreadList(0)) Then + ' li fermo + m_bStopProcess = True + ' verifico siano terminati + Dim bOneNotEnded As Boolean = True + While bOneNotEnded + bOneNotEnded = False + For Each Thread In ThreadList + If Not IsNothing(Thread) Then + If Thread.IsAlive Then + bOneNotEnded = True + End If + End If + Next + End While + ' pulisco la lista + For ThreadIndex = 0 To ThreadList.Count - 1 + ThreadList(ThreadIndex) = Nothing + Next + End If + If bStopMainProcess Then + m_bExecutionThreadStoped = True + Return + End If + End If + If Not bOk Then Thread.Sleep(10) + End While + + If bOk AndAlso (IsNothing(ThreadList) OrElse ThreadList.Count = 0 OrElse IsNothing(ThreadList(0))) Then + ThreadList = New Thread(m_MaxCamInstances - 1) {} + ThreadDataList = New ThreadData(m_MaxCamInstances - 1) {} + For nThreadIndex = 0 To m_MaxCamInstances - 1 + Dim ThreadId As Integer = nThreadIndex + ThreadList(nThreadIndex) = New Thread(Sub() + ThreadFunction(ThreadId) + End Sub) + ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA) + ' avvio thread di gestione della macchina che avvia la connessione + ThreadList(nThreadIndex).Start() + Thread.Sleep(10) + Next End If - ' se connessione non ok o processo fermato, fermo i thread - If Not bOk OrElse bStopMainProcess Then - If Not IsNothing(ThreadList) AndAlso ThreadList.Count > 0 AndAlso Not IsNothing(ThreadList(0)) Then - ' li fermo - m_bStopProcess = True - ' verifico siano terminati - Dim bOneNotEnded As Boolean = True - While bOneNotEnded - bOneNotEnded = False - For Each Thread In ThreadList - If Not IsNothing(Thread) Then - If Thread.IsAlive Then - bOneNotEnded = True - End If - End If - Next - End While - ' pulisco la lista - For ThreadIndex = 0 To ThreadList.Count - 1 - ThreadList(ThreadIndex) = Nothing - Next - End If - If bStopMainProcess Then - m_bExecutionThreadStoped = True - Return - End If - End If - If Not bOk Then Thread.Sleep(10) - End While - - If bOk AndAlso (IsNothing(ThreadList) OrElse ThreadList.Count = 0 OrElse IsNothing(ThreadList(0))) Then - ThreadList = New Thread(m_MaxCamInstances - 1) {} - ThreadDataList = New ThreadData(m_MaxCamInstances - 1) {} - For nThreadIndex = 0 To m_MaxCamInstances - 1 - Dim ThreadId As Integer = nThreadIndex - ThreadList(nThreadIndex) = New Thread(Sub() - ThreadFunction(ThreadId) - End Sub) - ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA) - ' avvio thread di gestione della macchina che avvia la connessione - ThreadList(nThreadIndex).Start() - Thread.Sleep(10) + ' se qualche processo in stop, lo faccio ripartire + For ThreadIndex = 0 To ThreadList.Count - 1 + Dim Thread = ThreadList(ThreadIndex) + If Thread.ThreadState = ThreadState.Stopped Then + Thread.Abort() + Dim ThreadId As Integer = ThreadIndex + Thread = New Thread(Sub() + ThreadFunction(ThreadId) + End Sub) + End If Next - End If - ' se qualche processo in stop, lo faccio ripartire - For ThreadIndex = 0 To ThreadList.Count - 1 - Dim Thread = ThreadList(ThreadIndex) - If Thread.ThreadState = ThreadState.Stopped Then - Thread.Abort() - Dim ThreadId As Integer = ThreadIndex - Thread = New Thread(Sub() - ThreadFunction(ThreadId) - End Sub) + If n30SecCounter <= 30 Then + n30SecCounter += 1 + Else + n30SecCounter = 1 End If - Next - If n30SecCounter <= 30 Then - n30SecCounter += 1 - Else - n30SecCounter = 1 - End If - Thread.Sleep(1000) + Thread.Sleep(1000) - End While + End While - End Sub + End Sub - Private Function GetFileContent(ByVal filePath As String, ByRef fileContent As String) As Boolean + Private Function GetFileContent(ByVal filePath As String, ByRef fileContent As String) As Boolean - Dim bOk As Boolean = File.Exists(filePath) - If bOk Then - Try - fileContent = File.ReadAllText(filePath) - Catch ex As Exception - bOk = False - fileContent = "" - End Try - End If - Return bOk - End Function + Dim bOk As Boolean = File.Exists(filePath) + If bOk Then + Try + fileContent = File.ReadAllText(filePath) + Catch ex As Exception + bOk = False + fileContent = "" + End Try + End If + Return bOk + End Function - Private Sub performBarAdvance() - synchronizationContext.Post(New SendOrPostCallback( + Private Sub performBarAdvance() + synchronizationContext.Post(New SendOrPostCallback( Sub(o) - tsProgBar.PerformStep() - If tsProgBar.Value >= tsProgBar.Maximum Then - tsProgBar.Value = 0 - End If + tsProgBar.PerformStep() + If tsProgBar.Value >= tsProgBar.Maximum Then + tsProgBar.Value = 0 + End If - tsProgBar.Invalidate() + tsProgBar.Invalidate() End Sub ), "") - End Sub + End Sub - Private Sub performUpdateUI() - synchronizationContext.Post(New SendOrPostCallback( + Private Sub performUpdateUI() + synchronizationContext.Post(New SendOrPostCallback( Sub(o) - 'verifico thread attivi e se calano --> riavvia.. - If ThreadCount() <> m_MaxCamInstances And Not m_bStopProcess Then - stopAllThreads() - Thread.Sleep(100) - startAllThreads() - End If + 'verifico thread attivi e se calano --> riavvia.. + If ThreadCount() <> m_MaxCamInstances And Not m_bStopProcess Then + stopAllThreads() + Thread.Sleep(100) + startAllThreads() + End If - lblRunning.Text = $"threads: {ThreadCount()}/{m_MaxCamInstances}" - lblRunning.Invalidate() - DisplayQueueStatus() - ' colore btn start / stop... - If m_bStopProcess Then + lblRunning.Text = $"threads: {ThreadCount()}/{m_MaxCamInstances}" + lblRunning.Invalidate() + DisplayQueueStatus() + ' colore btn start / stop... + If m_bStopProcess Then - StartProcess.BackColor = ButtonBase.DefaultBackColor - StartProcess.ForeColor = ButtonBase.DefaultForeColor - StopProcess.BackColor = Color.Green - StopProcess.ForeColor = Color.White - Else - StartProcess.BackColor = Color.Green - StartProcess.ForeColor = Color.White - StopProcess.BackColor = ButtonBase.DefaultBackColor - StopProcess.ForeColor = ButtonBase.DefaultForeColor - End If + StartProcess.BackColor = ButtonBase.DefaultBackColor + StartProcess.ForeColor = ButtonBase.DefaultForeColor + StopProcess.BackColor = Color.Green + StopProcess.ForeColor = Color.White + Else + StartProcess.BackColor = Color.Green + StartProcess.ForeColor = Color.White + StopProcess.BackColor = ButtonBase.DefaultBackColor + StopProcess.ForeColor = ButtonBase.DefaultForeColor + End If End Sub ), "") - End Sub + End Sub - Private Sub SetMaxCamInstances(value As Integer) - ' Numero di core logici da utilizzare (minimo tra presenti sul PC e imposti da INI) - Dim nMaxThread As Integer = Math.Min(Environment.ProcessorCount, value) - m_MaxCamInstances = nMaxThread - End Sub + Private Sub SetMaxCamInstances(value As Integer) + ' Numero di core logici da utilizzare (minimo tra presenti sul PC e imposti da INI) + Dim nMaxThread As Integer = Math.Min(Environment.ProcessorCount, value) + m_MaxCamInstances = nMaxThread + End Sub - Private Sub startAllThreads() - m_bStopProcess = False - '' fix colori - 'StartProcess.BackColor = Color.Green - 'StartProcess.ForeColor = Color.White + Private Sub startAllThreads() + m_bStopProcess = False + m_ExecutionThread = New Thread(Sub() + ExecutionProcess() + End Sub) - m_ExecutionThread = New Thread(Sub() - ExecutionProcess() - End Sub) - - m_ExecutionThread.SetApartmentState(ApartmentState.STA) - ' avvio thread di gestione della macchina che avvia la connessione - m_ExecutionThread.Start() - - ' avvio il timer di refresh - TimerProgBar.Enabled = True - TimerProgBar.Start() + m_ExecutionThread.SetApartmentState(ApartmentState.STA) + ' avvio thread di gestione della macchina che avvia la connessione + m_ExecutionThread.Start() #If False Then '' recupero Id dei DDF 'Dim sDdfRoot As String = "c:\EgtData\WebDoor\Ddf" @@ -563,266 +557,272 @@ Public Class ProcMan ' End If #End If - End Sub + End Sub - Private Sub StartProcess_Click(sender As Object, e As EventArgs) Handles StartProcess.Click - startAllThreads() - End Sub + Private Sub StartProcess_Click(sender As Object, e As EventArgs) Handles StartProcess.Click + startAllThreads() + End Sub - Private Sub StartUiThread() - ' avvio timer progBar - TimerUI.Enabled = True - TimerUI.Start() - End Sub + Private Sub StartUiThread() + ' avvio timer progBar + TimerUI.Enabled = True + TimerUI.Start() - Private Sub stopAllThreads() - m_bStopProcess = True + ' avvio il timer di refresh + TimerProgBar.Enabled = True + TimerProgBar.Start() + End Sub - While Not m_bExecutionThreadStoped - Thread.Sleep(20) - End While - m_ExecutionThread = Nothing - ' fix timer - TimerProgBar.Enabled = False - TimerProgBar.Stop() - End Sub + Private Sub stopAllThreads() + m_bStopProcess = True - Private Sub StopProcess_Click(sender As Object, e As EventArgs) Handles StopProcess.Click - stopAllThreads() - End Sub + While Not m_bExecutionThreadStoped + Thread.Sleep(20) + End While + m_ExecutionThread = Nothing + ' fix timer + TimerProgBar.Enabled = False + TimerProgBar.Stop() + 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 StopProcess_Click(sender As Object, e As EventArgs) Handles StopProcess.Click + stopAllThreads() + End Sub - Private Sub ThreadFunction(ThreadIndex As Integer) - Dim MyThreadData As New ThreadData - ThreadDataList(ThreadIndex) = MyThreadData - Dim sExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe" - Dim sCurrDdfDir As String = "c:\EgtData\WebDoor\Ddf" - Dim stopWatch As New Stopwatch() - Dim lExeTime As Long = 0 - Dim lOtherTime As Long = 0 + 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 - While Not m_bStopProcess - MyThreadData.SetThreadOperation(ThreadOperations.WaitingData) - ' se c'e' qualcosa da processare - If currWDC.numTask2proc > 0 Then - Dim LastRequest As Dictionary(Of String, String) = currWDC.queueList(1) - If LastRequest.Count > 0 Then - MyThreadData.SetThreadOperation(ThreadOperations.FoundRequest) - Dim Item As KeyValuePair(Of String, String) = LastRequest.First() - Dim bOk As Boolean = Not IsNothing(Item) - If bOk Then + Private Sub ThreadFunction(ThreadIndex As Integer) + Dim MyThreadData As New ThreadData + ThreadDataList(ThreadIndex) = MyThreadData + Dim sExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe" + Dim sCurrDdfDir As String = "c:\EgtData\WebDoor\Ddf" + Dim stopWatch As New Stopwatch() + Dim lExeTime As Long = 0 + Dim lOtherTime As Long = 0 - ' avvio cronometro - 'stopWatch.Reset() - stopWatch.Restart() - ' svuoto vecchio set file della porta richiesta - Dim fileList As String() = Directory.GetFiles(sCurrDdfDir, Item.Key + ".*") - ' elimino vecchi - If Not IsNothing(fileList) Then - For Each sFile In fileList - File.Delete(sFile) - Next - End If + While Not m_bStopProcess + MyThreadData.SetThreadOperation(ThreadOperations.WaitingData) + ' se c'e' qualcosa da processare + If currWDC.numTask2proc > 0 Then + Dim LastRequest As Dictionary(Of String, String) = currWDC.queueList(1) + If LastRequest.Count > 0 Then + MyThreadData.SetThreadOperation(ThreadOperations.FoundRequest) + Dim Item As KeyValuePair(Of String, String) = LastRequest.First() + Dim bOk As Boolean = Not IsNothing(Item) + If bOk Then - ' scrivo ddf - MyThreadData.SetThreadOperation(ThreadOperations.WritingDdf) - Dim sDdfPath As String = sCurrDdfDir & "\" & Item.Key & ".ddf" - Try - File.WriteAllText(sDdfPath, Item.Value) - Catch ex As Exception - bOk = False - End Try - - If bOk Then - MyThreadData.SetThreadOperation(ThreadOperations.ProcessingDdf) - - ' eseguo calcolo - Dim Proc As Process = New Process() - MyThreadData.SetProcess(Proc) - Proc.StartInfo.FileName = sExePath - Proc.StartInfo.Arguments = """C:\EgtData\WebDoor\Main.lua""" & " """ & sDdfPath & """" - Proc.StartInfo.UseShellExecute = False - - If Proc.Start() Then - - While Not Proc.HasExited - Thread.Sleep(1) - End While - MyThreadData.SetProcess(Nothing) - ' salvo exe time... - stopWatch.Stop() - lExeTime = stopWatch.ElapsedMilliseconds + ' avvio cronometro + 'stopWatch.Reset() stopWatch.Restart() - Dim procResults As New List(Of CalcResultDTO) - Dim currRes As New CalcResultDTO - Dim fContent As String = "" - MyThreadData.SetThreadOperation(ThreadOperations.ReadingSvg) - ' verifico esistenza file svg e lo carico - bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "svg"), fContent) - ' invio risposta - currRes.Validated = Proc.ExitCode = 0 AndAlso bOk - currRes.DoorIdVers = Item.Key - ' se NON fosse validato --> messo il messaggio... - If (currRes.Validated) Then - currRes.SvgGen = fContent - Else - bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "txt"), fContent) - currRes.ErrorMsg = fContent + ' svuoto vecchio set file della porta richiesta + Dim fileList As String() = Directory.GetFiles(sCurrDdfDir, Item.Key + ".*") + ' elimino vecchi + If Not IsNothing(fileList) Then + For Each sFile In fileList + File.Delete(sFile) + Next End If - MyThreadData.SetThreadOperation(ThreadOperations.SendResult) - procResults.Add(currRes) - Dim respPut As String = currWDC.SendProcResults(procResults) + ' scrivo ddf + MyThreadData.SetThreadOperation(ThreadOperations.WritingDdf) + Dim sDdfPath As String = sCurrDdfDir & "\" & Item.Key & ".ddf" + Try + File.WriteAllText(sDdfPath, Item.Value) + Catch ex As Exception + bOk = False + End Try - stopWatch.Stop() - lOtherTime = stopWatch.ElapsedMilliseconds - ' aggiorno thread display... - UpdateThreadList(Item.Key, lExeTime, lOtherTime) - ' cambio nomi file generati in old - Dim OldSvg As String = Path.ChangeExtension(sDdfPath, "svg") - Dim NewSvg As String = Path.GetDirectoryName(sDdfPath) & "\" & Path.GetFileNameWithoutExtension(sDdfPath) & "_old.svg" - Try - File.Delete(NewSvg) - Catch ex As Exception - End Try - Try - File.Delete(Path.ChangeExtension(NewSvg, "txt")) - Catch ex As Exception - End Try - Try - File.Delete(Path.ChangeExtension(NewSvg, "log")) - Catch ex As Exception - End Try - Try - File.Delete(Path.ChangeExtension(NewSvg, "nge")) - Catch ex As Exception - End Try - Try - File.Delete(Path.ChangeExtension(NewSvg, "ddf")) - Catch ex As Exception - End Try - Try - File.Move(OldSvg, NewSvg) - Catch ex As Exception - End Try - Try - File.Move(Path.ChangeExtension(OldSvg, "txt"), Path.ChangeExtension(NewSvg, "txt")) - Catch ex As Exception - End Try - Try - File.Move(Path.ChangeExtension(OldSvg, "log"), Path.ChangeExtension(NewSvg, "log")) - Catch ex As Exception - End Try - Try - File.Move(Path.ChangeExtension(OldSvg, "nge"), Path.ChangeExtension(NewSvg, "nge")) - Catch ex As Exception - End Try - Try - File.Move(Path.ChangeExtension(OldSvg, "ddf"), Path.ChangeExtension(NewSvg, "ddf")) - Catch ex As Exception - End Try - End If - stopWatch.Stop() - End If - End If + If bOk Then + MyThreadData.SetThreadOperation(ThreadOperations.ProcessingDdf) + + ' eseguo calcolo + Dim Proc As Process = New Process() + MyThreadData.SetProcess(Proc) + Proc.StartInfo.FileName = sExePath + Proc.StartInfo.Arguments = """C:\EgtData\WebDoor\Main.lua""" & " """ & sDdfPath & """" + Proc.StartInfo.UseShellExecute = False + + If Proc.Start() Then + + While Not Proc.HasExited + Thread.Sleep(1) + End While + MyThreadData.SetProcess(Nothing) + ' salvo exe time... + stopWatch.Stop() + lExeTime = stopWatch.ElapsedMilliseconds + stopWatch.Restart() + Dim procResults As New List(Of CalcResultDTO) + Dim currRes As New CalcResultDTO + Dim fContent As String = "" + MyThreadData.SetThreadOperation(ThreadOperations.ReadingSvg) + ' verifico esistenza file svg e lo carico + bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "svg"), fContent) + ' invio risposta + currRes.Validated = Proc.ExitCode = 0 AndAlso bOk + currRes.DoorIdVers = Item.Key + ' se NON fosse validato --> messo il messaggio... + If (currRes.Validated) Then + currRes.SvgGen = fContent + Else + bOk = GetFileContent(Path.ChangeExtension(sDdfPath, "txt"), fContent) + currRes.ErrorMsg = fContent + End If + MyThreadData.SetThreadOperation(ThreadOperations.SendResult) + + procResults.Add(currRes) + Dim respPut As String = currWDC.SendProcResults(procResults) + + stopWatch.Stop() + lOtherTime = stopWatch.ElapsedMilliseconds + ' aggiorno thread display... + UpdateThreadList(Item.Key, lExeTime, lOtherTime) + ' cambio nomi file generati in old + Dim OldSvg As String = Path.ChangeExtension(sDdfPath, "svg") + Dim NewSvg As String = Path.GetDirectoryName(sDdfPath) & "\" & Path.GetFileNameWithoutExtension(sDdfPath) & "_old.svg" + Try + File.Delete(NewSvg) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "txt")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "log")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "nge")) + Catch ex As Exception + End Try + Try + File.Delete(Path.ChangeExtension(NewSvg, "ddf")) + Catch ex As Exception + End Try + Try + File.Move(OldSvg, NewSvg) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "txt"), Path.ChangeExtension(NewSvg, "txt")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "log"), Path.ChangeExtension(NewSvg, "log")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "nge"), Path.ChangeExtension(NewSvg, "nge")) + Catch ex As Exception + End Try + Try + File.Move(Path.ChangeExtension(OldSvg, "ddf"), Path.ChangeExtension(NewSvg, "ddf")) + Catch ex As Exception + End Try + End If + stopWatch.Stop() + End If + End If + End If End If - End If - End While - MyThreadData.SetThreadOperation(ThreadOperations.Closed) + End While + MyThreadData.SetThreadOperation(ThreadOperations.Closed) - End Sub + End Sub - Private Sub TimerProgBar_Tick(sender As Object, e As EventArgs) Handles TimerProgBar.Tick - ' esegue refresh prog bar - performBarAdvance() - 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() - UpdateThreadCurrentStatus() - End Sub + Private Sub TimerUI_Tick(sender As Object, e As EventArgs) Handles TimerUI.Tick + ' effettuo refresh code e status thread + performUpdateUI() + UpdateThreadCurrentStatus() + 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() - SetMaxCamInstances(numReq) - 'startAllThreads() - End If - 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 + If m_bStopProcess = False Then + stopAllThreads() + End If + ' imposto + SetMaxCamInstances(numReq) + End If + End Sub - Private isUpdatingThreads As Boolean = False - ''' - ''' Esecuzione update display lista stato threads - ''' - Private Sub UpdateThreadList(tId As String, tExeCam As Long, tOther As Long) - synchronizationContext.Post(New SendOrPostCallback( + Private isUpdatingThreads As Boolean = False + ''' + ''' Esecuzione update display lista stato threads + ''' + Private Sub UpdateThreadList(tId As String, tExeCam As Long, tOther As Long) + synchronizationContext.Post(New SendOrPostCallback( Sub(o) - If Not isUpdatingThreads Then - isUpdatingThreads = True - ProcStats.RecordData(m_MaxCamInstances, tExeCam, tOther) - ProcStats.RecordList.Enqueue((tId, tExeCam, tOther)) - 'Begin the update - LISTThreadStatus.BeginUpdate() - LISTThreadStatus.Items.Clear() + If Not isUpdatingThreads Then + isUpdatingThreads = True + ProcStats.RecordData(m_MaxCamInstances, tExeCam, tOther) + ProcStats.RecordList.Enqueue((tId, tExeCam, tOther)) + 'Begin the update + LISTThreadStatus.BeginUpdate() + LISTThreadStatus.Items.Clear() - ' compilo in base al tipo di stat richiesta - If (chkStatAggr.Checked) Then - ' statistiche di sintesi - Dim sorted = From pair In ProcStats.ExeCumSum - Order By pair.Key - For Each item In sorted - LISTThreadStatus.Items.Add( + ' compilo in base al tipo di stat richiesta + If (chkStatAggr.Checked) Then + ' statistiche di sintesi + Dim sorted = From pair In ProcStats.ExeCumSum + Order By pair.Key + For Each item In sorted + LISTThreadStatus.Items.Add( New ListViewItem(New String() {item.Key, $"{item.Value.NumRec} x {item.Value.ExeTime / item.Value.NumRec:N2} ms", $"{item.Value.NumRec} x {item.Value.OthTime / item.Value.NumRec:N2} ms" })) - Next - Else - ' formato log - Dim maxItems As Integer = 15 - While ProcStats.RecordList.Count > maxItems - Dim oldItem As (String, Long, Long) = ("", 0, 0) - ProcStats.RecordList.TryDequeue(oldItem) - End While + Next + Else + ' formato log + Dim maxItems As Integer = 15 + While ProcStats.RecordList.Count > maxItems + Dim oldItem As (String, Long, Long) = ("", 0, 0) + ProcStats.RecordList.TryDequeue(oldItem) + End While - For Each item As (String, Long, Long) In ProcStats.RecordList.Reverse - LISTThreadStatus.Items.Add(New ListViewItem(New String() { + For Each item As (String, Long, Long) In ProcStats.RecordList.Reverse + LISTThreadStatus.Items.Add(New ListViewItem(New String() { item.Item1, $"{item.Item2} ms", $"{item.Item3} ms" })) - Next + Next - End If + End If - 'End the update - LISTThreadStatus.EndUpdate() - isUpdatingThreads = False - End If + 'End the update + LISTThreadStatus.EndUpdate() + isUpdatingThreads = False + End If End Sub ), "") - End Sub + End Sub #End Region @@ -868,72 +868,72 @@ Public Class ProcMan #Region "Private Structs" - Private Structure MyProc + Private Structure MyProc #Region "Public Fields" - Public bEnable As Boolean - Public nBar As Integer - Public Proc As Process - Public Thread As Thread + Public bEnable As Boolean + Public nBar As Integer + Public Proc As Process + Public Thread As Thread #End Region - End Structure + End Structure - ''' - ''' Esportazione statistiche attuali esecuzione - ''' - ''' - ''' - Private Sub btnExportStats_Click(sender As Object, e As EventArgs) Handles btnExportStats.Click - ' statistiche di sintesi - Dim sorted = From pair In ProcStats.ExeCumSum - Order By pair.Key - ' preparo il file export... - Dim fileName As String - Dim adesso As DateTime = DateTime.Now - fileName = Path.Combine("C:\Temp\", $"WDC_Stats_{adesso:yyyyMMdd-HHmmss}.csv") - Dim sb As StringBuilder = New StringBuilder - sb.AppendLine("Threads;Samples;ExeTime;OtherTime;FullTime") - For Each item In sorted - ' preparo la linea CSV... - sb.AppendLine($"{item.Key};{item.Value.NumRec};{item.Value.ExeTime / item.Value.NumRec:N2};{item.Value.OthTime / item.Value.NumRec:N2};{(item.Value.ExeTime + item.Value.OthTime) / item.Key:N2}") - Next - ' scrivo! - File.WriteAllText(fileName, sb.ToString()) - End Sub + ''' + ''' Esportazione statistiche attuali esecuzione + ''' + ''' + ''' + Private Sub btnExportStats_Click(sender As Object, e As EventArgs) Handles btnExportStats.Click + ' statistiche di sintesi + Dim sorted = From pair In ProcStats.ExeCumSum + Order By pair.Key + ' preparo il file export... + Dim fileName As String + Dim adesso As DateTime = DateTime.Now + fileName = Path.Combine("C:\Temp\", $"WDC_Stats_{adesso:yyyyMMdd-HHmmss}.csv") + Dim sb As StringBuilder = New StringBuilder + sb.AppendLine("Threads;Samples;ExeTime;OtherTime;FullTime") + For Each item In sorted + ' preparo la linea CSV... + sb.AppendLine($"{item.Key};{item.Value.NumRec};{item.Value.ExeTime / item.Value.NumRec:N2};{item.Value.OthTime / item.Value.NumRec:N2};{(item.Value.ExeTime + item.Value.OthTime) / item.Key:N2}") + Next + ' scrivo! + File.WriteAllText(fileName, sb.ToString()) + End Sub - Private Sub ProcMan_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing - ' forzo chiusura threads! - stopAllThreads() - End Sub + Private Sub ProcMan_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing + ' forzo chiusura threads! + stopAllThreads() + End Sub - Private Sub chkAutoRestart_CheckedChanged(sender As Object, e As EventArgs) Handles chkAutoRestart.CheckedChanged - CheckStartAutoRestart() - End Sub + Private Sub chkAutoRestart_CheckedChanged(sender As Object, e As EventArgs) Handles chkAutoRestart.CheckedChanged + CheckStartAutoRestart() + End Sub - Private Sub CheckStartAutoRestart() - TimerCheck.Enabled = chkAutoRestart.Checked - If chkAutoRestart.Checked Then - TimerCheck.Start() - Task.Delay(500) - startAllThreads() - Else - TimerCheck.Stop() - End If - End Sub + Private Sub CheckStartAutoRestart() + TimerCheck.Enabled = chkAutoRestart.Checked + If chkAutoRestart.Checked Then + TimerCheck.Start() + Task.Delay(500) + startAllThreads() + Else + TimerCheck.Stop() + End If + End Sub - Private Sub TimerCheck_Tick(sender As Object, e As EventArgs) Handles TimerCheck.Tick - restartAll() - End Sub + Private Sub TimerCheck_Tick(sender As Object, e As EventArgs) Handles TimerCheck.Tick + restartAll() + End Sub - Private Sub restartAll() - ' eseguo riavvio forzato ogni 30 sec! - stopAllThreads() - Task.Delay(500) - startAllThreads() - End Sub + Private Sub restartAll() + ' eseguo riavvio forzato ogni 30 sec! + stopAllThreads() + Task.Delay(500) + startAllThreads() + End Sub #End Region