Delphi 6:非VCL线程上触发的断点停止主线程重绘 [英] Delphi 6 : breakpoint triggered on non-VCL thread stops main thread repaints

查看:97
本文介绍了Delphi 6:非VCL线程上触发的断点停止主线程重绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目前正在大量处理的多线程Delphi 6 Pro应用程序.如果我在主线程(VCL线程)的上下文中运行的任何代码上设置断点,则不会有任何问题.但是,如果在我的其他线程之一中的任何代码上触发了断点,则从断点继续执行应用程序之后,不再重新绘制主线程(包括主窗体)上的VCL组件.该应用程序没有死,因为其他后台代码一直在运行,仅在主线程中运行.就像Windows消息调度程序已损坏或处于休眠状态一样.

I have a multi-threaded Delphi 6 Pro application that I am currently working on heavily. If I set a breakpoint on any code that runs in the context of the Main thread (VCL thread) I don't have any problems. However, if a breakpoint is triggered on any code in one of my other threads, after I continue the application from the breakpoint, all repaints to the VCL components on the main thread (including the main form) don't happen anymore. The application isn't dead because other background code keeps running, just the main thread. It's as if the windows message dispatcher has been corrupted or rendered dormant.

请注意,在此应用程序中,我需要通过在主窗体上的allocateHwnd()分配自己的WndProc(),因为我需要捕获某些已注册的消息.我从该WndProc()调度我处理的所有自定义消息,如果当前消息未由我的代码处理,则通过调用主窗体的继承WndProc()来传递该消息.如果我确实处理当前消息,则只需从WndProc()返回,并将Msg.Result设置为1即可告诉调度程序该消息已处理.我不能简单地重写TForm WndProc()而不是分配自己的WndProc(),因为出于某些原因,Delphi VCL不会传递通过Windows API RegisterWindowMessage()调用实例化的注册消息.

Note, in this application I allocate my own WndProc() via allocateHwnd() on the main form because I need to catch certain registered messages. From that WndProc() I dispatch any custom messages I handle and if the current message is not handled by my code, I pass the message on by calling the main form's inherited WndProc(). If I do handle the current message I simply return from my WndProc() with Msg.Result set to 1 to tell the dispatcher that the message was handled. I can't simply override the TForm WndProc() instead of allocating my own WndProc() because for some reason the Delphi VCL does not pass through registered messages instantiated with the Windows API RegisterWindowMessage() call.

有人在类似的情况下遇到过这种情况吗?如果是,您是如何解决的?

Has anybody experienced this in similar context and if so, what did you do to fix it?

-罗莎尔(Roscherl)

-- roscherl

推荐答案

自从您调用AllocateHWnd以来,这意味着您已经创建了另一个窗口.您不仅要处理发送到该窗口的消息,然后将其转发到表单的窗口.这样做,您一定会在程序中搞砸,尽管我不确定具体如何.绘画问题听起来很合理.您应该确保这实际上只是绘画问题,而不是主线程仍处于挂起状态.调试器应该能够告诉您. (您应该调用DefWindowProc来使分配的窗口处理您不准备处理的消息.返回1不会告诉调度程序任何信息;调度程序不在乎-调用SendMessage的人都想知道结果.)

Since you call AllocateHWnd, that means you've created another window. You mustn't just take the messages that were addressed to that window and forward them to your form's window. Doing that, you're bound to screw things up in your program, although I'm not sure exactly how. Painting problems sound plausible. You should make sure it's really just painting problems and not that your main thread is still suspended. The debugger should be able to tell you that. (You should call DefWindowProc to make your allocated window handle messages you're not prepared to handle yourself. And returning 1 doesn't tell the dispatcher anything; the dispatcher doesn't care — whoever called SendMessage wants to know the result.)

我向您保证,表格完全能够接收注册的窗口消息.覆盖WndProc或为WindowProc属性分配一个新值(并记住保存旧值,以便您在处理自己的消息后可以调用它).问题的根源在其他地方.

I promise you that forms are completely capable of receiving registered window messages. Override WndProc or assign a new value to the WindowProc property (and remember to save the old value so you can call it after handling your own messages). The source of your problem lies elsewhere.

这篇关于Delphi 6:非VCL线程上触发的断点停止主线程重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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