将 SetThreadExecutionState 与尚未阻止睡眠模式的应用程序一起使用
Use SetThreadExecutionState with app that doesn't already prevent sleep mode
在 Windows 7 和 10 上,Spotify 应用程序不会阻止显示屏关闭或系统进入睡眠模式(至少在我使用的 3 windows 机器上是这样).有没有办法启动应用程序并将 SetThreadExecutionState 函数合并到该线程中,以防止在应用程序 运行 时显示休眠?或者任何其他可以实现该结果的函数?
我目前使用两个单独的 .bat 文件来启动和关闭应用程序,这两个文件改变了睡眠定时器,但这非常笨拙,所以我更喜欢一个合适的应用程序来完成它。
此 c# 解决方案不使用 SetThreadExecutionState 函数,但您提到您已经有 .bat 文件来更改睡眠定时器,因此您可以将其中的命令复制到此处。
C# 控制台应用程序:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var spotify = new Process();
spotify.StartInfo.FileName = "Spotify.exe";
spotify.StartInfo.Arguments = "-v -s -a";
Process.Start("powercfg", "-CHANGE -monitor-timeout-ac 0");
spotify.Start();
spotify.WaitForExit();
var exitCode = spotify.ExitCode;
spotify.Close();
Process.Start("powercfg", "-CHANGE -monitor-timeout-ac 1");
}
}
}
添加更多 Process.Start 行来改变休眠等
在 Windows 7 和 10 上,Spotify 应用程序不会阻止显示屏关闭或系统进入睡眠模式(至少在我使用的 3 windows 机器上是这样).有没有办法启动应用程序并将 SetThreadExecutionState 函数合并到该线程中,以防止在应用程序 运行 时显示休眠?或者任何其他可以实现该结果的函数?
我目前使用两个单独的 .bat 文件来启动和关闭应用程序,这两个文件改变了睡眠定时器,但这非常笨拙,所以我更喜欢一个合适的应用程序来完成它。
此 c# 解决方案不使用 SetThreadExecutionState 函数,但您提到您已经有 .bat 文件来更改睡眠定时器,因此您可以将其中的命令复制到此处。 C# 控制台应用程序:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var spotify = new Process();
spotify.StartInfo.FileName = "Spotify.exe";
spotify.StartInfo.Arguments = "-v -s -a";
Process.Start("powercfg", "-CHANGE -monitor-timeout-ac 0");
spotify.Start();
spotify.WaitForExit();
var exitCode = spotify.ExitCode;
spotify.Close();
Process.Start("powercfg", "-CHANGE -monitor-timeout-ac 1");
}
}
}
添加更多 Process.Start 行来改变休眠等