[英]Is there a way to monitor the state of a console application?
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: 我可以想到的唯一方法是:
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?
有没有一种方法可以检测ClickOnce应用程序是否正在运行,或者是否可以通过其他方法来访问“消息”或日志以显示进度?
Note - I am also looking into using NodeJS to do this, but unsure if it has this capability. 注意-我也正在研究使用NodeJS来执行此操作,但是不确定它是否具有此功能。
First, you should consider writing this as a Windows service instead of a console application. 首先,您应该考虑将此作为Windows服务而不是控制台应用程序编写。
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.
这将打开使用系统监视器/性能监视器作为监视工具的大门,因此无需编写任何客户端代码。
There are at least two ways to achieve that: 至少有两种方法可以实现:
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. 您的控制台应用程序在运行期间会写入一些日志,一些状态文件,以便其他进程可以读取这些文件并了解该控制台进程中发生的情况。
Implement an IPC mechanism. 实施IPC机制。 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#?
它可能会帮助您了解在C#中进行进程间通信的最简单方法是什么? .
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.