0

I have a local service (written in C#), running on Windows 7, 64-bit, that monitors a folder (via a file system watcher) and when the appropriate file type (.xml, in this case) appears it calls a reader application with the full path of the document file as a parameter. Currently the reader app is Notepad. Everything seems to work fine; when the file is dropped into the folder I can see in Task Manager that Notepad is running, but I can’t see it! It’s running in the background with no UI. I’ve tried other file reader apps, so it’s not that, it must be something to do with the way it’s being called. This is the current code, but I’ve tried other variations, particularly with the ProcessStartInfo.

var workingDirectory = Path.GetDirectoryName(this.readingApplication) ?? Path.GetTempPath();

this.eventLog1.WriteEntry(
           "In OpenTheMessage. Working Directory: " + workingDirectory,
           EventLogEntryType.Information,
           ++this.eventId);

var info = new ProcessStartInfo
{
   FileName = this.readingApplication, 
   Arguments = xmlFileMessage, 
   WindowStyle = ProcessWindowStyle.Normal, 
   UseShellExecute = true,
   WorkingDirectory = workingDirectory            
};

this.eventLog1.WriteEntry(
           "In OpenTheMessage. Run: " + this.readingApplication + " " + xmlFileMessage,
           EventLogEntryType.Information,
           ++this.eventId);

Process.Start(info);

I can see from the event log that the program flow is correct. I can even copy the command from the log into Windows Run and it works. What is going on here?

Steven Digby
  • 85
  • 1
  • 7
  • That's simply not how services work, see [How can I run an EXE program from a Windows Service using C#?](http://stackoverflow.com/questions/5307968/how-can-i-run-an-exe-program-from-a-windows-service-using-c) – Alex K. Nov 03 '16 at 13:52
  • Consider what happens if there is no/multiple users logged on ... Is a service appropriate for your use case? - If so you would run a desktop app as an intermediary for each logged on user and use an IPC mechanism to talk to the service. – Alex K. Nov 03 '16 at 13:53
  • I think that your question was answered in [this link](http://stackoverflow.com/questions/3798612/service-starting-a-process-wont-show-gui-c-sharp). Good luck. – Incepter Nov 03 '16 at 14:03
  • 1
    Thank you Alex/Mohamed. I am disappointed to find I was on a coding dead end these last two days - but I can probably cannibalise the code for a Windows App which seems to be the correct solution. – Steven Digby Nov 03 '16 at 15:27

0 Answers0