在 WPF 中动态查看 Windows UpTime
我想要获得如下图所示的 Windows UpTime
我正在使用 NetFrameWork 3 我使用此代码来显示 Windows 的 UpTime
PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time");
upTime.NextValue();
TimeSpan ts = TimeSpan.FromSeconds(upTime.NextValue());
UpTime.Text = "UpTime: " + ts.Days + ":" + ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds;
但我收到的内容是固定的并且不会自行更新 我想同时更改Windows的正常运行时间 请指导我
I want to get Windows UpTime like the picture below
I am using NetFrameWork 3
I use this code to display UpTime for Windows
PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time");
upTime.NextValue();
TimeSpan ts = TimeSpan.FromSeconds(upTime.NextValue());
UpTime.Text = "UpTime: " + ts.Days + ":" + ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds;
But what I receive is fixed and does not update itself
I want to change the uptime of Windows here at the same time
please guide me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码看起来不错。唯一缺少的是您应该定期调用它来更新 UI。
看一下示例: https://learn.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatchertimer?view=windowsdesktop-6.0
需要注意的是,因为您想要更新 UI:
您只需稍作修改的代码可能如下所示:
Your code looks good. The only thing missing is that you should call it periodically to update the UI.
Take a look at the example: https://learn.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatchertimer?view=windowsdesktop-6.0
Important to note, since you want to update UI:
Your only slightly modified code might then look something like this: