Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Windows Service clean up threads on stop

WHat would be the way to properly clean up these threads in the Windows Service OnStop?

Dim phoneWorkerThread As New Threading.Thread(AddressOf startPhoneMonitoring)
phoneWorkerThread.Name = "Thread " + " | [" + dataRowString + "] " + System.Guid.NewGuid.ToString()
phoneWorkerThread.IsBackground = True
phoneWorkerThread.Start(sendRow)

Open in new window

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

If I remember correctly, you maintain a list of these threads right? You would need to abort all these threads before the service dies.
Avatar of Larry Brister

ASKER

CodeCruiser,
  So along these lines (using the dictionaty list)

            Dim t As Thread
            For Each t In Diagnostics.Process.GetCurrentProcess().Threads
                t.Abort()
            Next t
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bingo!  Thanks