I created a Windows Service that watches a directory using FileSystemWatcher and when a file is put into the folder it zips it.
All the functionality is in a class I created named FileProcessor.
When I create a Console app that uses FileProcessor the automated zipping works great. However, when I run the class in the Windows Service it never works.
Check the account and directory your service is running under – does it have permission and visibility to the target directory?
Add some diagnostics to the class so that you can see what it’s trying to do, and output error information (you are handling any possible OS errors under
FileSystemWatcher, right?). You’ll need these anyway when the service goes live. Compare the output when running as service versus in test.Add a
System.Threading.Thread.Sleep(15000)to your class so that when it’s invoked by your service, you have time to attach the debugger to work out what’s going on.