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