我是 C# 新手,我正在 C#.net windows 应用程序上开发项目,因为我需要从我的日程安排文件中读取下一个日程安排时间,如果下一个小时没有日程安排,我的系统不需要唤醒直到在计划文件中定义的下一个计划时间到达。我的系统需要关闭,并且在关闭之前需要设置系统唤醒定时器。如何在关闭我的电脑之前按时设置系统。我通过 python 脚本在 Linux 系统中做了同样的事情,方法是在位置
按时编写系统。/sys/class/rtc/rtc0/wakealaram
我只是在这个位置写下一个系统的时间并关闭系统,系统可以在到达wakealaram
文件中给出的时间时自动启动。我需要使用 C# 在 Windows 系统中执行相同的操作。
问问题
353 次
1 回答
-1
看看下面。
#region Clock Reset
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short Year;
public short Month;
public short DayOfWeek;
public short Day;
public short Hour;
public short Minute;
public short Second;
public short Milliseconds;
}
[DllImport("kernel32.dll")]
public extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);
private void ResetSystemTime(DateTime tdt)
{
try
{
SYSTEMTIME time = new SYSTEMTIME();
time.Day = (short)tdt.Day;
time.Month = (short)tdt.Month;
time.Year = (short)tdt.Year;
time.Hour = (short)tdt.Hour;
time.Minute = (short)tdt.Minute;
time.Second = (short)tdt.Second;
SetSystemTime(ref time);
}
catch (Exception ex)
{
MessageBox.Show("System time reset Exception: " + ex.Message);
}
}
#endregion
于 2013-06-29T10:36:57.137 回答