views:

313

answers:

2

I coding a service application that have two threads. First thread, show a form with label. Second thread, query ADO.

First thread always freezing with Hourglass cursor and no label caption.

Please help.

+4  A: 

If you're trying to show a form from within a thread that is not the main thread, then you will run into strange things like this. The most notable of which is that if the form and label are created in the non-main thread, then you don't have a message loop to process the messages. If the form was created in the main thread, but you're attempting to show it from the non-main thread, then it is likely a dead lock due to how Windows deals with messages and threads.

When a window handle is created it is tied to the thread on which it was created. This means that Windows will ensure that any messages sent to that handle are processed on that thread.

I would strongly suggest you read up on how window messages, message queues, and handles all interact and function in a multi-threaded environment. If not done correctly, you are assured of some very odd and possibly unpredictable behavior.

Allen Bauer
Looks like this guy would benefit from a Giant Book, like one of Marco Cantu's giant 800+ page Delphi books.
Warren P
A: 

I would call your condition either a Race, a Deadlock, or some other kind of error like that. As Allen says, if the background thread makes ANY direct access to the VCL controls, without using TThread.Synchronize(myMethod) to invoke the myMethod that touches your VCL foreground, then this alone would cause your trouble.

Post more information, including a sample of your code please.

Warren P