开机时间少于1秒,而且不会变得无响应 [英] OnTime for less than 1 second without becoming Unresponsive

查看:78
本文介绍了开机时间少于1秒,而且不会变得无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户窗体,该窗体每100毫秒运行一次脚本.该脚本处理用户窗体上的图像并用于对其进行动画处理,而窗体继续接收用户输入(鼠标单击和按键).这一直持续到关闭用户窗体为止.尽管Application.OnTime似乎效果最好,但它只能在1秒或更长的时间值上持续运行.

I have a userform which runs a script every 100ms. The script handles images on the userform and is used to animate them, while the form continues to receive user input (mouse clicks and key presses). This continues until the userform is closed. While Application.OnTime seems to work best, it only operates consistently on time values of 1 second or more.

当我使用类似的东西

Sub StartTimer()
    Application.OnTime now + (TimeValue("00:00:01") / 10), "Timer"
End Sub

Private Sub Timer()
    TheUserForm.ScreenUpdate
    Application.OnTime now + (TimeValue("00:00:01") / 10), "Timer"
End Sub

并在用户窗体中调用StartTimer,Excel变得非常无响应,并且每秒调用"Timer"的次数比应有的次数多.

and call StartTimer in the userform, Excel becomes very unresponsive and "Timer" is called many more times per second than it should.

尽管脚本以正确的间隔运行,但使用睡眠"功能也会导致程序也无响应.

Using the Sleep function causes the program to become unresponsive too, although the script is run with the right interval.

是否有解决方法?预先感谢!

Is there a workaround for this? Thanks in advance!

推荐答案

OnTime只能安排以1秒为增量运行.当您尝试将其计划为1/10秒时,实际上是将其计划为0秒,即它立即再次运行,从而消耗了所有资源.

OnTime can only be scheduled to run in increments of 1 second. When you attempt to schedule it at 1/10th second, you actually schedule at 0 seconds, ie it runs again immediately, consuming all resources.

简短的回答,您不能使用OnTime每1/10秒运行一次事件.

Short answer, you cannot use OnTime to run an event every 1/10 second.

还有其他方法,请参见 CPearson 以使用对Windows API的调用
Public Declare Function SetTimer Lib "user32" ...

There are other ways, see CPearson for using a call to Windows API
Public Declare Function SetTimer Lib "user32" ...

这篇关于开机时间少于1秒,而且不会变得无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆