Bonjour

J'ai hérité d'un code VB que je dois modifier. Le code crée et démarre un Thread (sur un serveur dans ce cas) dans une boucle infinie, mais il n'y a pas de procédure d'arrêt du thread dans le module :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Imports System.Threading
 
Module Module1
    Sub Main()
        Dim fnLib As New functionLibrary
        fnLib.WriteLog("OnStart : Begin")
        ' === 
        ' === Ensure our registry has been set up
        ' === 
        Dim dbConnString As String = fnLib.getConfigValue("dbConnectionString")
        If Len(Trim(dbConnString)) < 1 Then
            fnLib.WriteLog("smWEBservice is incorrectly configured.  No database connection string specified in the cfg file.")
        Else
            Dim fred As Threading.Thread
            Dim smMain As New smWEBservice_main
            fred = New Thread(AddressOf smMain.beginProtectedLoop)
            fred.IsBackground = True
            fnLib.WriteLog("OnStart : Starting main thread")
            fred.Start()
            fnLib.WriteLog("OnStart : Complete")
        End If
        ' === 
        ' === Loop forever (all processing is in the fred thread)
        ' === 
        While True
            System.Threading.Thread.Sleep(10000)
        End While
    End Sub
End Module
Comment puis-je "tuer" le Thread ?

Merci

Lena