VB6 Timer 控件是否创建单独的线程? [英] Does VB6 Timer control create separate thread?

查看:16
本文介绍了VB6 Timer 控件是否创建单独的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB6 Timer 控件启动时是否创建单独的处理线程?

Does the VB6 Timer control create a separate processing thread when it starts?

推荐答案

VB6 Timer 控件不是在后台线程上运行的某种忙等待循环.他们根本就没有真正奔跑".

VB6 Timer controls are not some kind of busy-wait loop running on a background thread. They don't really "run" at all.

据我所知,当您设置 Enabled = True(或更改 Interval,如果它为 0)时,控件会调用 SetTimer().当您设置 Enabled = False(或将 Interval 设置为 0)时,它会调用 KillTimer().

As far as I can tell when you set Enabled = True (or change Interval if it was 0) the control makes a SetTimer() call. When you set Enabled = False (or set Interval to 0) it makes a KillTimer() call.

普通的 VB6 消息循环(当然在 UI 线程上运行)通过将传入的 WM_TIMER 消息分派给相关的 Timer 的事件处理程序代码来处理它们.因此,事件处理程序中的代码在 UI 线程上运行,阻止进一步的消息处理,直到退出.由于遗留原因(16 位 VB 和 Windows),间隔似乎被截断为无符号的 16 位值?

The normal VB6 message loop (which of course runs on the UI thread) handles incoming WM_TIMER messages by dispatching them to the associated Timer's event handler code. Thus the code inside your event handler runs on the UI thread, blocking further message processing until exit. Interval seems to be chopped to an unsigned 16-bit value - for legacy reasons (16-bit VB and Windows)?

在您的程序中编写的任何诸如忙等待循环的代码(您的所有代码都在 UI 线程上运行)当然会阻塞消息处理,从而产生定时器不会触发"的错觉.由于 WM_TIMER 是低优先级消息,因此当您绑定 UI 线程时,它们不会在消息队列中堆积得很深:

Anything like a busy-wait loop coded in your program (all of your code runs on the UI thread) will of course block message processing, giving the illusion that Timers do not "fire." Since WM_TIMER is a low priority message they do not stack up deeply in the message queue while you have the UI thread bound up:

WM_TIMER 消息是低优先级消息.GetMessage 和PeekMessage 函数仅在没有其他消息时发布此消息更高优先级的消息在线程的消息队列中.

The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue.

这篇关于VB6 Timer 控件是否创建单独的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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