我知道这个问题以前曾在不同的情况下被问过。
我想编写一个 C# 程序,在 Windows Vista 或 Windows 7 计算机完全启动时弹出一条消息。 (万事俱备,硬盘安定,电脑有反应)
目前我正在使用计时器。我想知道是否有一种方法可以确定所有服务何时启动或类似的东西?
编辑:
我有一些似乎工作得很好的东西:
using System.Diagnostics;
public partial class Form1 : Form
{
private PerformanceCounter cpuCounter;
private PerformanceCounter diskCounter;
private int seconds;
private int lowUsage;
private const String timeMsg = "Waiting for Boot: ";
private const String cpuMsg = "CPU: ";
private const String diskMsg = "Disk: ";
public Form1()
{
InitializeComponent();
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
diskCounter = new PerformanceCounter();
diskCounter.CategoryName = "PhysicalDisk";
diskCounter.CounterName = "% Disk Time";
diskCounter.InstanceName = "_Total";
seconds = 0;
lowUsage = 0;
Timer timer = new Timer();
timer.Interval = 1000;
timer.Tick += tick;
timer.Start();
timeLabel.Text = timeMsg + seconds;
cpuLabel.Text = cpuMsg + "100%";
diskLabel.Text = diskMsg + "100%";
StartPosition = FormStartPosition.CenterScreen;
}
private void tick(Object o, EventArgs e)
{
seconds++;
int cpu = (int)cpuCounter.NextValue();
int disk = (int)diskCounter.NextValue();
if (cpu < 5 && disk < 5) lowUsage++;
else lowUsage = 0;
if (lowUsage >= 5 && seconds > 35) Application.Exit();
timeLabel.Text = timeMsg + seconds;
cpuLabel.Text = cpuMsg + cpu + "%";
diskLabel.Text = diskMsg + disk + "%";
}
}
最佳答案
您可以尝试休息 CPU 使用率、硬盘驱动器使用率或两者的组合。如果什么都没发生,我的电脑使用率只有 1% 到 4%。在启动过程中它要高得多。可能需要做一些数学运算才能找到尖峰和稳定性的趋势。无论如何,我就是这样去做的。我不知道服务选项。我有点怀疑是否有一种方法可以询问每个人是否已完成加载并完成他们的工作,即使您可以获得他们的列表也是如此。
关于c# - 确定 Windows 计算机何时完全启动并开始响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21819155/