本文介绍了使用计时器检测应用中的空闲时间的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序.在此应用程序中,我要关闭该应用程序&如果用户闲置5分钟,则激活登录表单.
为了这个目的,我使用了计时器.但是通过这种方式,我必须对每种形式的应用程序都使用计时器.
有什么办法可以使用一个计时器来完成整个应用程序?
请不要建议我在新表单中添加计时器,并使用每个表单调用该表单,
因为我尝试过,这是一种错误的方式,并且无法真正起作用.

谢谢alot

i have an application . in this application i want to close the application & activate login form if the user be idle for 5 minute.
for this aim i used a timer .but by this way i have to use timer for each forms of application.
is there any way to use one timer for whole applicatin???
plz dont suggest me that add a timer to a new form and call that form with each form,
becuse I tryed it , it''s a wrong way and doesnt work truly.

thanks alot

推荐答案

Partial Friend Class MyApplication

    Public WithEvents idleTimer As Timer

    Private Sub MyApplication_Startup(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
        idleTimer = New Timer
        idleTimer.Interval = 5 * 60 * 1000 '(300,000mseconds = 5 minutes)

        idleTimer.Start() 'start the timer

    End Sub

    Private Sub idleTimer_Tick() Handles idleTimer.Tick
        'Do what ever you need to when it times out
    End Sub

End Class



您只需要确保任何用户交互,打开表单,按键,单击按钮等,重置计时器即可.



You just need to make sure that any user interaction, opening forms, keypresses, button clicks etc, reset the timer


这篇关于使用计时器检测应用中的空闲时间的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:34