c# - 确定 Windows 计算机何时完全启动并开始响应

标签 c# windows boot

我知道这个问题以前曾在不同的情况下被问过。

我想编写一个 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/

相关文章:

linux - 我的 rc.local 文件 (Ubuntu) 有什么问题?

C# 如何保存运行时字体设置

c# - .net 应用程序 CPU 使用率高

c# - 映射的网络驱动器,File.Exists 奇怪的行为

windows - 如何通过 Windows 任务计划程序执行 Postgresql 过程

linux - 模拟 Linux 内核时黑屏

c# - 如何在 C# 中启动 'Scheduled Task Wizard'?

Windows 批处理文件压缩,然后 ftp 文件

java - 如果 BufferedWriter 仍然打开,为什么 BufferedReader 会失败?

python - 在 linux 上登录时运行我的 Python 脚本