简体   繁体   English

有没有办法监视控制台应用程序的状态?

[英]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: 我可以想到的唯一方法是:

  1. Create a text/xml file when application is started 启动应用程序时创建一个text / xml文件
  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? 有没有一种方法可以检测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: 至少有两种方法可以实现:

  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. 实施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.

相关问题 监控应用程序内存使用情况的正确方法是什么? - What is the right way to monitor application memory usage? 有什么方法可以监视Windows应用程序的安装数量? - Any way to monitor install numbers of a Windows Application? 正确的方法来实现C#控制台应用程序? - Correct way to implement C# console application? 是否有在.NET Console应用程序中使用Dispatcher的干净方法? - Is there a clean way of using Dispatcher in a .NET Console application? 在控制台应用程序中使用 Razor 的最佳方式是什么 - What is the best way to use Razor in a console application 有什么方法可以将字符串拖到控制台应用程序上吗? - Is there any way to drag strings onto a console application? 有没有办法在控制台应用程序中对用户进行身份验证? - is there a way to do authenticate a user in a console application? 有没有办法在控制台应用程序中处理http发布请求? - Is there a way to handle a http post request in a console application? 有什么方法可以防止控制台应用程序关闭? - Is there any way to prevent console application to close? 有没有其他方法可以在控制台应用程序中禁用加密 - Is there any other way to disable encryption in console application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM