2

Is there a way to monitor the state of a console application?

I am trying to build a user interface which shows whether or not a console application is currently running on the server (processing files). If it is running, I would like to show the current state: how many files processed, what file currently being processed, etc.

The only way that I can think of doing this:

  1. Create a text/xml file when application is started
  2. Update text file with information about current state for each object it processes
  3. Delete text file when the application is finished processing

To me, this doesn't seem like a very good or efficient way to do it. Is there a way to detect if the ClickOnce application is running, and perhaps some other way to access the "Messages" or Log of it to show the progress?

Note - I am also looking into using NodeJS to do this, but unsure if it has this capability.

Cody
  • 8,686
  • 18
  • 71
  • 126

2 Answers2

4

First, you should consider writing this as a Windows service instead of a console application.

That said, scraping a log file that your application is writing is a reasonable approach. Just ensure that it never gets too big.

Alternatively, you could look at using custom performance counters. That would open the door to using System Monitor/perfmon as your monitoring tool, so no need to write any client code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RicknBaker
  • 41
  • 1
  • Why the immediate suggestion to write it as a Windows Service? – Cody May 21 '13 at 12:12
  • 1
    Many reasons, among them: Designed to run unattended; No need to have a logged on user; Built in utilities available to start, stop and pause the service. – RicknBaker May 21 '13 at 13:46
1

There are at least two ways to achieve that:

  1. Your console application writes some logs, some state files, during its run, so other processes can read those files and understand what is going on in that console process.

  2. Implement an IPC mechanism. There are different ways to do that. It may help you look in What is the easiest way to do inter process communication in C#?.

Community
  • 1
  • 1
Tigran
  • 61,654
  • 8
  • 86
  • 123
  • From a quick look - it looks like IpcChannel class and Microsoft Messaging Queueing are two similar ways to do that? – Cody May 21 '13 at 11:58
  • @DoctorOreo: they *look* similiar, but for sure there will be some difference. – Tigran May 21 '13 at 12:03