十五、定时函数

十五、定时函数

1、CPU()

功  能:得到自当前应用程序启动后开始CPU所消耗的时间,以毫秒为单位。

语  法:CPU()

返回值:Long。返回自当前应用程序启动后开始CPU所消耗的时间,以毫秒为单位。

示  例:These statements determine the amount of CPU time that elapsed while a group of statements executed:

// Declare ll_start and ll_used as long integers.

long ll_start, ll_used

// Set the start equal to the current CPU usage.

ll_start = Cpu()

... // Executable statements being timed

// Set ll_used to the number of CPU seconds

// that were used (current CPU time - start).

ll_used = Cpu() - ll_start

 

2、Idle()

功  能:该函数在用户每次活动(例如,按键盘、移动鼠标等)后重置定时器,n秒后触发应用对象的Idle事件。

语  法:Idle ( n )

参  数:n:指定空闲时间间隔,以秒为单位。该参数的值设置为0时,停止空闲检测,不再触发应用对象的Idle事件。

返回值:Integer。函数执行成功时返回1,此时启动定时器。如果不能启动定时器或定时器未启动而n的值指定为0时,函数返回-1。如果任何参数的值为NULL,Idle()函数返回NULL。

用  法:利用Idle()函数,应用程序可以构造自己的屏幕保护程序,避免安全数据的泄露。

当使用Idle()函数已经启动了定时器后,如果再次以非0参数调用Idle()函数,那么该函数重设时间间隔,但并不启动新的定时器。

Idle()函数启动定时器后,如果在指定的时间间隔(从用户最近一次操作算起)内没有操作应用程序,那么就触发应用对象的Idle事件,在这个事件中可以编写关闭窗口、退出数据库登录等一系列代码,然后使用Restart()函数重新启动应用程序,起到保密的目的。

发生下述任何情况时,系统自动重置定时器(即重新开始计时):

  1. 用户在该应用程序的任何窗口内移动鼠标或单击鼠标(双击鼠标时首先触发单击事件)
  2. 在该应用程序的某个窗口是当前窗口时用户按下了任意一个或多个键
  3. 在该应用程序的窗口最小化时,用户在该应用的图标上单击鼠标或移动鼠标
  4. 在该应用程序的窗口最小化并且该应用程序是当前应用程序(应用名称被加亮显示)时,用户按了任何按键
  5. 可视数据窗口检索数据时引起的编辑控件(指漂浮在数据窗口当前行/列上的编辑控件)重绘操作

示  例:1、This statement sends an Idle event after five minutes of inactivity:

Idle(300)

2、This statement turns off idle detection:

Idle(0)

3、This example shows how to use the Idle event to stop the application and restart it after two minutes of inactivity. This is often used for computers that provide information in a public place.

Include this statement in the script for the application's Open event:

Idle(120) // Sends an Idle event after 2 minutes.

Include these statements in the script for the application's Idle event to terminate the application and then restart it:

// Statements to set the database to the desired

// state

...

Restart() // Restarts the application

 

3、Timer()

功  能:在指定的时间间隔内反复触发指定窗口的定时器事件。

语  法:Timer ( interval {, windowname } )

参  数:interval:指定两次触发Timer事件之间的时间间隔,有效值在0到65之间。如果该参数的值指定为0,那么关闭定时器,不再触发指定窗口的Timer事件windowname:窗口名,指定时间间隔到时要触发哪个窗口的Timer事件。省略该参数时,触发当前窗口的Timer事件。

返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果任何参数的值为NULL,Timer()函数返回NULL。

用  法:使用Timer()函数可以周期性地触发指定窗口的Timer事件,这样,每当时间间隔过去时,应用程序都可以完成一些周期性的工作,比如绘制简单动画等。将Timer()的interval参数设置为非0值时启动定时器并开始计时;将该函数的interval参数设置为0时关闭定时器,终止计时任务。

需要注意的是,在Microsoft Windows系统中,该函数能够计时的最小时间间隔为0.055秒(约1/18秒),如果把interval参数的值设置小于0.055,那么该定时器将每隔0.055秒触发一次窗口的Timer事件。

Microsoft Windows 3.x最多只支持系统中同时启动16个定时器。

示  例:1、This statement triggers a Timer event every two seconds in the active window:

Timer(2)

2、This statement stops the triggering of the Timer event in the active window:

Timer(0)

3、These statements trigger a Timer event every half second in the window w_Train:

Open(w_Train)

Timer(0.5, w_Train)

4、This example causes the current time to be displayed in a StaticText control in a window. Calling Timer in the window's Open event script starts the timer. The script for the Timer event refreshes the displayed time.

In the window's Open event script, the following code displays the time initially and starts the timer:

st_time.Text = String(Now(), "hh:mm")

Timer(60)

In the window's Timer event, which is triggered every minute, this code displays the current time in the StaticText st_time:

st_time.Text = String(Now(), "hh:mm")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值