自己做的在用户不进行任何操作时,在设定时间后自动休眠,重启,关机。虽然不怎么实用,但其核心还是值得初学者学习的,就是用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)