将动作延迟一段时间

发布于 2024-12-22 20:54:48 字数 264 浏览 6 评论 0原文

我目前正在开发一个屏幕保护程序启动器,但我想延迟屏幕保护程序的激活一段时间,以确保鼠标位置仍然处于激活它的位置,以防止意外激活。我正在考虑某种线程在执行前检查鼠标位置 x 秒,这是否是一个明智的解决方案?

我不是在写屏幕保护程序,我已经编写了一个应用程序,以便 当您将鼠标移动到桌面的指定角落时, 屏幕保护程序打开...我想知道如何添加延迟 将鼠标移动到该角落以防止意外启动 屏幕保护程序

如果是这样怎么办?

I am currently working on a screensaver launcher, but I want to delay the activation of the screensaver for a period of time to ensure the mouse position is still in the position to activate it, to prevent accidental activation. I am thinking some kind of thread to check the position of the mouse for x secs before execution, would this be a sensible solution?

I'm not writing a screensaver, I have written an application so that
when you move your mouse to a designated corner of your desktop, the
screensaver comes on... I want to know how to add a delay to when you
move the mouse into that corner to prevent accidental launching of the
screensaver

If so how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清醇 2024-12-29 20:54:48

这样当您将鼠标移动到桌面的指定角落时,屏幕保护程序就会出现...

当鼠标到达那里时,设置一个布尔值和一个计时器。使任何鼠标操作都清除布尔值。
仅当计时器触发并且您的旗帜仍然存在时,才继续。

换句话说,使用一个小状态机。

so that when you move your mouse to a designated corner of your desktop, the screensaver comes on...

When the mouse gets there, set a boolean and a timer. Make any mouse action clear the boolean.
Only when the timer fires and your flag is still there, proceed.

In other words, use a little state machine.

梦里°也失望 2024-12-29 20:54:48

这是伪代码

   var CurrentMouse = ...; // Get mouse coordinates.
   ThreadPool.QueueUserWorkItem(        
   (s) => {
            Thread.Sleep(500); // Half a second

        //  if (Mouse did not move)
        //     Launch Screen Saver

   });

编辑:
请注意,这并不是说调用回 gui 层或线程锁定。请参阅我的博客文章 使用 ThreadPool、匿名委托和锁的 C# 多线程 来了解这种情况的灵感,该文章确实显示正确的锁定。

Here is pseudo code

   var CurrentMouse = ...; // Get mouse coordinates.
   ThreadPool.QueueUserWorkItem(        
   (s) => {
            Thread.Sleep(500); // Half a second

        //  if (Mouse did not move)
        //     Launch Screen Saver

   });

EDIT:
Note this doesn't speak to invoking back to gui layer or thread locking. See the inspiration for this situation on my blog article entitled C# MultiThreading Using ThreadPool, Anonymous Delegates and Locks which does show proper locking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文