C#获取系统空闲时间

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值