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.
Sounds to me like file permissions might be screwing you up. Which account is the service running under?
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.
try to debug you service as spender said - run service. Put a debug point at place in code to check. Press Ctrl + Alt + P in Visual studio this will give you attach process screen.
Check in - Show processes in all users AND Show processes in all sessions - Checkbox. Try to find your service in - Available processes list and click "Attach"
now put a file in the folder and the debugger will take you to VS at the breakpoint and try to debug it i m sure you will find what the problem is.
精彩评论