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

推荐订阅源

博客园 - Franky
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
WordPress大学
WordPress大学
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
T
Tor Project blog
阮一峰的网络日志
阮一峰的网络日志
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Hacker News
The Hacker News
F
Full Disclosure
有赞技术团队
有赞技术团队
H
Help Net Security
Security Latest
Security Latest
P
Palo Alto Networks Blog
MyScale Blog
MyScale Blog
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
P
Privacy International News Feed
P
Proofpoint News Feed
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
罗磊的独立博客
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
爱范儿
爱范儿
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
The Last Watchdog
The Last Watchdog
N
Netflix TechBlog - Medium
D
DataBreaches.Net
L
LINUX DO - 热门话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
Lohrmann on Cybersecurity
O
OpenAI News
S
SegmentFault 最新的问题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - 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)  评论()    收藏  举报