0

I've developed a service that watches one directory and then if a file is created or changed it will spin up another small c# script that will determine what to do with that file. I need this to be constantly listening to the directory at all times(even on start up of the server) because a file could be generated in this directory at literally any time.

I've searched and tried a few things but each time. The service will run then a file will be generated...then it launches the other C# script and does what it needs to with that file and then the service stops. So next time something happens in that directory nothing happens. Is there something I'm missing? How would I go about doing this?

Mickey Sly
  • 429
  • 2
  • 6
  • 21
  • 1
    A service that crashes with an unhandled exception doesn't make any sound. It just stops to do what it was supposed to do. The Windows event log will contain an event for that. Improve the quality of the event info by writing an event handler for the AppDomain.CurrentDomain.UnhandledException event. – Hans Passant Jan 23 '14 at 20:10
  • thank you kind sir. This was the answer. :) I checked the event log there was something in there about an IO.Exception...I only used IO once in the program and it wasn't even needed when i commented it out it worked flawlessly! Thank you! – Mickey Sly Jan 23 '14 at 20:41

1 Answers1

0

So, your C# service will be stopped working after the first time that it runs your C# script? I think it should related to your service configuration.

Checkout these links to see how you should create a service through C# : http://www.codeproject.com/Articles/3938/Creating-a-C-Service-Step-by-Step-Lesson-I http://www.codeproject.com/Articles/106742/Creating-a-simple-Windows-Service http://www.codeproject.com/Articles/400697/WCF-Service-Creation-With-Csharp

I hope it helps you to find your mistake.

(If there's sth else, tell in comment)

  • 1
    Also: make sure the watcher isn't faulted by hooking up the error event, see example in accepted answer here http://stackoverflow.com/questions/6943908/using-filesystemwatcher-with-multiple-files – Anders Forsgren Jan 23 '14 at 20:03
  • So when you created a Service and start it. Its supposed to run forever by default? – Mickey Sly Jan 23 '14 at 20:11