c# - 从 C# 休眠计算机

标签 c# windows winforms

我想通过单击 C# Windows 窗体应用程序中的按钮让我的计算机休眠。

private void Button1_Click(object sender, EventArgs e)
{
    //Hibernate the computer
}

最佳答案

使用Application.SetSuspendState方法:

private void button1_Click(object sender, EventArgs e)
{
    Application.SetSuspendState(PowerState.Hibernate, true, true);
}

或者:

using System.Diagnostics;
Process.Start("shutdown", "/h /f");

关于c# - 从 C# 休眠计算机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37764445/

相关文章:

c# - 在代码隐藏中上下滚动列表框

c# - 理解 InvalidAsynchronousStateException 的发生

c# - 将数据绑定(bind)到 Windows 窗体 TabControl

c# - 如何为 Windows 创建自定义 Shell 上下文处理程序?

c# - 前台和后台线程

c# - Win10 UWP、Prism/Unity 和单元测试以及类库、静默失败

windows - 如何在 BATCH 脚本中使用随机数?

c++ - SFML 未定义对 impl 的引用

windows - Windows 7 上的 Cabal 测试

c# - 在 C# Windows 窗体中绘制大量图像