How to gracefully stop a windows service with multi-threaded processing on a timer thread? Is it possible to add some infinite loop logic in the OnStop method to postpone the service shutting down.
            Asked
            
        
        
            Active
            
        
            Viewed 1,607 times
        
    2 Answers
1
            
            
        You have to handle cancellation of the threads in your service in the OnStop() method.
Try some logic with ManualResetEvent or AutoResetEvent
You probably also have to stop your timer.
 
    
    
        Jens Granlund
        
- 4,950
- 1
- 31
- 31
0
            
            
        You will probably need to use some sort of flag to indicate whether a Thread should stop or not. There is already a similar question on SO - here
 
    
    
        Community
        
- 1
- 1
 
    
    
        codingbadger
        
- 42,678
- 13
- 95
- 110
 
    