G
Guest
I've written a Windows Service program that monitors a directory using the FileSystemWatcher class. The monitoring is done on it's own thread. Once a particular files gets added(created) to the directory, the program calls a routine using ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf module.sub)). That routine creates an object of another class. The problem is that classes' Finalize method is not called until the Windows Service is stopped. Does anybody know why that object is not released until the service is stopped and a way for me to ensure that classes' Finalize method gets called
Here is a summerized version of the code
1. The OnStart of the service creates a reference to the monitor class and creates a thread for the main routine of the monitor class to run on
2. The main routine of the monitor class creates a FileSystemWatcher object and performs a do loop waiting for a file to get created using WaitForChanged(WatcherChangeTypes.Created
3. Once a file is added to the directory, the ThreadPool is used to call a routine in another module using ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf module.subroutine)
4. That routine creates a reference to let's say X class
The problem is that X classes' Finalize method never gets called until the Windows Service is stopped. I hope this is somewhat clear and makes sense to someone. Any help is appreciated.
Here is a summerized version of the code
1. The OnStart of the service creates a reference to the monitor class and creates a thread for the main routine of the monitor class to run on
2. The main routine of the monitor class creates a FileSystemWatcher object and performs a do loop waiting for a file to get created using WaitForChanged(WatcherChangeTypes.Created
3. Once a file is added to the directory, the ThreadPool is used to call a routine in another module using ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf module.subroutine)
4. That routine creates a reference to let's say X class
The problem is that X classes' Finalize method never gets called until the Windows Service is stopped. I hope this is somewhat clear and makes sense to someone. Any help is appreciated.