0

I've been stuck with this annoying problem for the last couple of hours, and I've just exhausted my resources. This is what's going on:

I have a Windows Service created using the 4.0 .NET framework. The main functionality of this service is to read all .txt files contained in a folder, validate the formatting of these files and then send them to another folder, create an xml file from those files, and then create a pdf file using the information contained in the xml; I'm using the Report.NET library (http://sourceforge.net/projects/report/) to create these .pdf files.

When I run the service, it does everything it's supposed to do except generate the .pdf file, and then I get the following error:

"Service on Local Computer started and then stopped. Some service stop automatically if they have no work to do."

Also, I forgot to mention, if I debug the windows service using Visual Studio, everything works as intended and the .pdf files are generated correctly.

I've already tried attaching the "main" function to a thread and then starting that thread on the OnStart() method, but that doesn't seem to work, neither adding a timer.

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
  • Have you tried debugging it? Sounds like an exception might be occurring. – Matt Davis Jan 09 '14 at 15:37
  • 1
    Check Windows Event log for exception in your service. – realnero Jan 09 '14 at 15:38
  • Put a try-catch block in your thread function and write any exceptions to the Windows event log. Off the cuff, you might have a path problem (or something similar) that only shows itself when you run outside the debugger. – Matt Davis Jan 09 '14 at 15:46
  • I actually did tried that, it says that i have a "null-reference exception" when the application reaches the "createPDF" method which is odd, i tried the same code on a console application and it is working properly. – David Elizalde Jan 09 '14 at 15:54
  • Have you checked [this](http://stackoverflow.com/q/12209075/909742) post? – Andrea Jan 09 '14 at 15:56
  • So...i just added a timer and captured the process in a try-catch block and now it's working properly. That's odd, that's just the way i had it originally: protected override void OnStart(string[] args) { // if (args[0] == "DEBUG") { Debugger.Launch(); } Timer time; time = new Timer(); time.Interval = 5000; try { time.Elapsed += new ElapsedEventHandler(DoYaThing); time.Start(); } catch(Exception e) { }} – David Elizalde Jan 09 '14 at 16:30
  • Code working differently if you put in a delay is a symptom of a race condition. – Dour High Arch Jan 09 '14 at 18:42

0 Answers0