跟踪流程的最佳方法
在我的咨询公司,我们使用一些非常昂贵的模拟软件。我需要一种方法来监视这些应用程序/进程的使用情况(在后台,使用 C#)。这个想法是,当有人运行特定应用程序时,系统会提示他们输入作业名称。然后,当他们关闭程序时,他们使用该程序的时间量将被发送到驻留在网络上的数据库。这样,我们就可以通过按美元/分钟向客户收费来收回软件成本。除了提示之外,该程序必须对用户几乎不可见。
我已经想到了几种方法来做到这一点,但我不确定什么是最好的:
有一个在启动时运行的程序,只有一个托盘图标。我想我必须有一个后台工作人员连续监视进程,也许使线程休眠,并每 5 分钟左右检查一次进程。
在启动时使用 Quartz.net 之类的东西,并带有托盘图标。如果这甚至适用于每分钟。我对 Quartz.net 不是很熟悉,但从我的研究来看,它看起来可能是可行的。
使用某种 Windows 服务。这是我最不熟悉的。
哪种方法最有成效?谢谢
At my consulting company, we use some very expensive simulation software. I need a means to monitor the usage of these applications/processes (in the background, using C#). The idea is that when someone runs a particular application, they are prompted to enter the job name. Then, when they close the program, the amount of time they used it is sent to a database residing on the network. This way we can recoup the costs of the software by charging our clients on a $/min basis. Aside from the prompt, the program must be nearly invisible to users.
I have thought of a few ways of doing this, but I'm not sure what's best:
Have a program that runs on startup, with only a tray icon. I suppose then I would have to have a backgroundworker monitoring the processes continuously, perhaps sleeping the thread, and checking the processes every 5 minutes or so.
Use something like Quartz.net, on startup and with a tray icon. If this is even applicable on a minute-by-minute basis. I am not very familiar with Quartz.net, but from my research it looks maybe do-able.
Use some kind of Windows Service. This one I am least familiar with.
Which method would be most fruitful? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写一个简单的 C# 程序,该程序在执行时收集所需的信息和开始时间。
然后通过使用 Process 类来执行模拟软件。
使用
WaitForExit()
等待进程结束,并根据执行时间等执行所需的操作。因此,本质上您最终会得到一个应用程序,该应用程序只是收集所需的信息,启动主应用程序,等待应用程序结束并在总执行时间内执行所需的操作。至于对用户不可见,您可以在等待应用程序结束时最小化主窗口(它也充当收集所需信息的表单)。
下面是在 C# 中启动可执行文件的一个小示例。
You could write a simple C# program that upon execution collects the required information and start time.
Then by using the
Process
class you execute the simulation software.Wait for the process to end using
WaitForExit()
and do whatever is needed with the execution time etc.So essentially you end up with an application that simply collects the required information, launches the main application, waits for the application to end and does whatever is needed with the total execution time. As far as being invisible to the user, you could just minimize the main window ( which also acts as the form for collecting the needed info ) while waiting for the application to end.
Here is a small example of starting an executable within C#.