views:

71

answers:

3

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.

+5  A: 

Sounds to me like file permissions might be screwing you up. Which account is the service running under?

spender
+3  A: 

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.

Steve Townsend
+1 for the good old Thread.Sleep([many seconds]) trick. Even better when, once you've sorted out the problem, you then release the bugger with that in and never quite find the time to take it out again!
Andras Zoltan
@Andras Zoltan - typically I only put this in for Debug build to forestall embarrassment
Steve Townsend
Alternately, you can have it execute `Debugger.Break` (http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx), which will prompt you to attach to it. You'd also need to make sure it's allowed to interact with the desktop.
Steven Sudit
@Steve Townsend - yes same here; only after about 3 of my earliest services went out like this though...
Andras Zoltan
A: 

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.

J Sinh