- piccole modifiche per miglioramento gestione thread e restart
This commit is contained in:
@@ -181,16 +181,18 @@ Public Class ProcMan
|
||||
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
|
||||
If Not bStopMainProcess AndAlso Not m_bStopProcess Then
|
||||
' 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
|
||||
Else
|
||||
bOk = True
|
||||
End If
|
||||
' se connessione non ok o processo fermato, fermo i thread
|
||||
If Not bOk OrElse bStopMainProcess Then
|
||||
@@ -239,13 +241,19 @@ Public Class ProcMan
|
||||
' se qualche processo in stop, lo faccio ripartire
|
||||
For ThreadIndex = 0 To ThreadList.Count - 1
|
||||
Dim Thread = ThreadList(ThreadIndex)
|
||||
If Thread.ThreadState = ThreadState.Stopped OrElse Thread.ThreadState = ThreadState.Aborted OrElse
|
||||
If Not IsNothing(Thread) Then
|
||||
If Thread.ThreadState = ThreadState.Stopped OrElse Thread.ThreadState = ThreadState.Aborted OrElse
|
||||
Thread.ThreadState = ThreadState.Suspended Then
|
||||
Thread.Abort()
|
||||
Dim ThreadId As Integer = ThreadIndex
|
||||
Thread = New Thread(Sub()
|
||||
ThreadFunction(ThreadId)
|
||||
End Sub)
|
||||
Thread.Abort()
|
||||
Thread.Sleep(1000)
|
||||
While Not Thread.ThreadState = ThreadState.Aborted
|
||||
Thread.Sleep(1000)
|
||||
End While
|
||||
Dim ThreadId As Integer = ThreadIndex
|
||||
Thread = New Thread(Sub()
|
||||
ThreadFunction(ThreadId)
|
||||
End Sub)
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
If n30SecCounter <= 30 Then
|
||||
@@ -291,9 +299,9 @@ Public Class ProcMan
|
||||
Sub(o)
|
||||
'verifico thread attivi e se calano --> riavvia..
|
||||
If ThreadCount() <> m_MaxCamInstances And Not m_bStopProcess Then
|
||||
stopAllThreads()
|
||||
Thread.Sleep(100)
|
||||
startAllThreads()
|
||||
'stopAllThreads()
|
||||
'Thread.Sleep(100)
|
||||
'startAllThreads()
|
||||
End If
|
||||
|
||||
lblRunning.Text = $"threads: {ThreadCount()}/{m_MaxCamInstances}"
|
||||
@@ -324,6 +332,7 @@ Public Class ProcMan
|
||||
|
||||
Private Sub startAllThreads()
|
||||
m_bStopProcess = False
|
||||
m_bExecutionThreadStoped = False
|
||||
m_ExecutionThread = New Thread(Sub()
|
||||
ExecutionProcess()
|
||||
End Sub)
|
||||
@@ -579,7 +588,11 @@ Public Class ProcMan
|
||||
m_bStopProcess = True
|
||||
|
||||
While Not m_bExecutionThreadStoped
|
||||
Thread.Sleep(20)
|
||||
Thread.Sleep(100)
|
||||
End While
|
||||
m_ExecutionThread.Abort()
|
||||
While Not m_ExecutionThread.ThreadState = ThreadState.Aborted
|
||||
Thread.Sleep(100)
|
||||
End While
|
||||
m_ExecutionThread = Nothing
|
||||
' fix timer
|
||||
@@ -918,12 +931,14 @@ Public Class ProcMan
|
||||
Private Sub CheckStartAutoRestart()
|
||||
TimerCheck.Enabled = chkAutoRestart.Checked
|
||||
If chkAutoRestart.Checked Then
|
||||
If m_ExecutionThread.ThreadState = ThreadState.Aborted OrElse m_ExecutionThread.ThreadState = ThreadState.Stopped OrElse
|
||||
m_ExecutionThread.ThreadState = ThreadState.Suspended Then
|
||||
If Not IsNothing(m_ExecutionThread) AndAlso (m_ExecutionThread.ThreadState = ThreadState.Aborted OrElse m_ExecutionThread.ThreadState = ThreadState.Stopped OrElse
|
||||
m_ExecutionThread.ThreadState = ThreadState.Suspended) Then
|
||||
stopAllThreads()
|
||||
Thread.Sleep(200)
|
||||
m_ExecutionThread.Abort()
|
||||
Thread.Sleep(200)
|
||||
While Not IsNothing(m_ExecutionThread)
|
||||
Thread.Sleep(100)
|
||||
End While
|
||||
Thread.Sleep(100)
|
||||
startAllThreads()
|
||||
End If
|
||||
TimerCheck.Start()
|
||||
@@ -938,8 +953,14 @@ Public Class ProcMan
|
||||
|
||||
Private Sub restartAll()
|
||||
' eseguo riavvio forzato ogni 30 sec!
|
||||
stopAllThreads()
|
||||
Task.Delay(500)
|
||||
If Not IsNothing(m_ExecutionThread) Then
|
||||
stopAllThreads()
|
||||
Thread.Sleep(200)
|
||||
While Not IsNothing(m_ExecutionThread)
|
||||
Thread.Sleep(100)
|
||||
End While
|
||||
Thread.Sleep(100)
|
||||
End If
|
||||
startAllThreads()
|
||||
End Sub
|
||||
|
||||
|
||||
Reference in New Issue
Block a user