zoukankan      html  css  js  c++  java
  • C# 定时无操作则退出登陆,回到登陆界面。

    有时候根据需求需要为程序添加在规定的时间内无操作则退出当前的登陆程序的功能,如下代码模拟描述的需求功能。

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace LockScreenMsg
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                label1.Height = 200;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            struct LASTINPUTINFO
            {
                [MarshalAs(UnmanagedType.U4)]
                public int cbSize;
                [MarshalAs(UnmanagedType.U4)]
                public uint dwTime;
            }
    
            [DllImport("user32.dll")]
            static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
    
            static long GetLastInputTime()
            {
                LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
                vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
                if (!GetLastInputInfo(ref vLastInputInfo))
                {
                    return 0;
                }
                return Environment.TickCount - (long)vLastInputInfo.dwTime;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                timer1.Enabled = true;
            }
    
            public string isNull = null;
            private void timer1_Tick(object sender, EventArgs e)
            {
               long time=GetLastInputTime()/1000;
                
                this.label1.Text = string.Format("用户已经{0}秒没有操作了", time);
               if (time >= 20)
               {
                    this.Close();
               }
            }
        }
    }
    
  • 相关阅读:
    k8s的快速使用手册
    prometheus
    k8s的存储卷
    nfs共享文件服务搭建
    k8s的基本使用
    Linux shell if [ -n ] 正确使用方法
    CURL使用方法详解
    LINUX下NFS系统的安装配置
    RedHat 6.2 Linux修改yum源免费使用CentOS源
    css清除浮动float的三种方法总结,为什么清浮动?浮动会有那些影响?
  • 原文地址:https://www.cnblogs.com/snail0404/p/6433125.html
Copyright © 2011-2022 走看看