惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Proofpoint News Feed
D
Docker
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
Forbes - Security
Forbes - Security
MongoDB | Blog
MongoDB | Blog
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
A
About on SuperTechFans
Schneier on Security
Schneier on Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
IT之家
IT之家
The Last Watchdog
The Last Watchdog
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
Project Zero
Project Zero
B
Blog
Recorded Future
Recorded Future
博客园_首页
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
SegmentFault 最新的问题
Security Archives - TechRepublic
Security Archives - TechRepublic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hacker News: Front Page
T
Threatpost
H
Heimdal Security Blog
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog

博客园 - chengeng

让SVN可以修改提交log Python开发环境搭建 ubuntu 安装mysql Android Studio汉化备忘 DataConvert VS2022,IF条件为Flase也进入断点,设置方法 在CentOS上,查看CPU、内存和磁盘的指标命令 mysql 常用语句 MQTT服务器订阅消息例子 Java 异步调用方法 修改Web.config,IIS启动速度提升60倍 Windows smbv1共享协议开启 windows 10 激活 c#将一个类型对象数据赋值到另一个类型对象(名字相同的情况) 根据json内容更新表的一行,字段数量不固定,但名称需要一致 Windows 服务启动共享目录 FastReport 打印弹框,无法关闭(自己特定的场景,做个备忘,请勿参考) MDns C# 实现 Makaretu.Dns.Multicast WinForm截屏 C#根据json内容动态生成SQL语句,字段数量可以不一样 金蝶云星空BOS平台官网知识 .Net Framework 离线安装包
WinForm 指定时间没有操作键盘鼠标,弹出屏幕保护
chengeng · 2024-03-18 · via 博客园 - chengeng
 #region 屏幕保护
 System.Timers.Timer timerRunScreenSaverTask = null;
 F_ScreenSaver f_ScreenSaver = null;
 private void RunScreenSaverTask() 
 {
     if (timerRunScreenSaverTask == null)
     {
         timerRunScreenSaverTask = new System.Timers.Timer();
         timerRunScreenSaverTask.Interval = 1000;
         timerRunScreenSaverTask.Elapsed += TimerRunScreenSaverTask_Elapsed;
         timerRunScreenSaverTask.Start();
     }
 }

 private void TimerRunScreenSaverTask_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     RunScreenSaver();
 }

 private void RunScreenSaver() 
 {
     long lastInputTimeToNow = GetLastInputTime();
     if (lastInputTimeToNow >= 5 * 1000)
     {
         Console.WriteLine("走If分支" + "空闲时间" + lastInputTimeToNow.ToString());
         string imagePath = Application.StartupPath + @"\Update\ScreenSaver.png";
         if (File.Exists(imagePath) == false)
         {
             return;
         }

         if (f_ScreenSaver == null)
         {
             f_ScreenSaver = new F_ScreenSaver();
             f_ScreenSaver.TopLevel = true;
             f_ScreenSaver.ShowDialog();
         }
         else
         {
             f_ScreenSaver.ShowDialog();
         }
     }
     else
     {
         Console.WriteLine("走else分支" + "空闲时间" + lastInputTimeToNow.ToString());
         if (f_ScreenSaver != null)
         {
             f_ScreenSaver.Hide();
         }
     }
 }

 [DllImport("user32.dll")]
 static extern bool GetLastInputInfo(ref LastInputInfo plii);
 static long GetLastInputTime()
 {
     LastInputInfo vLastInputInfo = new LastInputInfo();
     vLastInputInfo.Size = Marshal.SizeOf(vLastInputInfo);
     if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
     return Environment.TickCount - (long)vLastInputInfo.Time;
 }

 [StructLayout(LayoutKind.Sequential)]
 struct LastInputInfo
 {
     [MarshalAs(UnmanagedType.U4)]
     public int Size;
     [MarshalAs(UnmanagedType.U4)]
     public uint Time;
 }
 #endregion

posted @ 2024-03-18 10:50  chengeng  阅读(90)  评论()    收藏  举报