Lee*_*Lee 165
本System.Diagnostics.Process类具有包含起始时间,你可以用它来计算它已经运行了多长时间的属性:
var current = System.Diagnostics.Process.GetCurrentProcess();
DateTime startedAt = current.StartTime
Run Code Online (Sandbox Code Playgroud)
Nik*_*wal 33
使用StopWatch此功能的类.
即使相当过度,即使用户更改时钟,或者即使在此过程中有一些夏令时更改,它也将始终有效.- Julien Lebosquain(评论我的回答.)
您可以Static DateTime Variable为项目创建一个,并将日期时间存储在Main Class的构造函数中.引用此静态变量,并与当前时间进行比较可帮助您实现结果