自己做的在用户不进行任何操作时,在设定时间后自动休眠,重启,关机。虽然不怎么实用,但其核心还是值得初学者学习的,就是用user32.dll获取系统空闲时间。下面是主要的实现代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace test
{
public partial class Form1 : Form
{
Process p = new Process();
string fun;
ulong time;
public struct lastInputInfo
{
public int cbsize;
public uint dwTime;
}
[DllImport("user32.dll")]
private static extern bool GetLastInputInfo(ref lastInputInfo plii);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
}

这篇博客介绍了如何使用C#编程语言结合user32.dll动态链接库,来获取计算机系统的空闲时间。作者分享了一个在用户无操作达到一定时间后执行自动休眠、重启或关机的功能,尽管实用性有限,但对于初学者来说,它是理解如何利用系统API获取空闲时间的一个良好示例。
最低0.47元/天 解锁文章
536

被折叠的 条评论
为什么被折叠?



