我有一个桌面应用程序,需要一直运行.但是有人关闭了该应用程序. [英] I have a desktop application which need to be running at all times. But some one closes the application.

查看:176
本文介绍了我有一个桌面应用程序,需要一直运行.但是有人关闭了该应用程序.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中有一个桌面应用程序,该应用程序必须一直运行 .但是有人关闭了该应用程序.我找不到使用 TASK MANAGER 关闭应用程序的时间吗?我需要找到系统事件日志或任何类似的内容(没有外部应用程序),它们显示了应用程序启动和关闭的时间.在此先感谢

I have a desktop application in C# which needs to be running at all times. But some one closes the application. I can not find out at what time the application is closed using the TASK MANAGER ? I need to find the system event logs or anything similar(no external application) which shows when the application started and when it was closed. Thanks in advance

推荐答案

使用计时器 [^ ],然后每隔一分钟或五分钟将应用程序状态写入文本文件或数据库中.
参考:
Use Timer[^] and write the application status on every minute or 5 minutes... to a text file or database.
ref:
http://social.msdn.microsoft.com/Forums/windows/en-US/43daf8b2-67ad-4938-98f7-cae3eaa5e63f/how-to-use-timer-control-in-c?forum=winforms[^]


我要做的就是使用主窗体关闭事件来在txt文件中将其关闭的时间以及表单加载或构造函数在其启动时的时间写入txt文件中.这样,您将获得带有开始/停止时间的日志.
What i would do is using the main form closing event to write in a txt file the time when it is closing and the form load or the constructor to write when it starts. This way you''ll have a log with times of start/stop.


当您的应用程序启动时,将时间写入文件.然后使用Application.ApplicationExit事件来通知它关闭的时间.
http://msdn.microsoft.com /en-us/library/system.windows.forms.application.applicationexit(v=vs.110).aspx [
When your application starts, write the time to a file. Then use Application.ApplicationExit event to notice the time when it closes.
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.applicationexit(v=vs.110).aspx[^]


这篇关于我有一个桌面应用程序,需要一直运行.但是有人关闭了该应用程序.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆