Question

I have thread where downloading xml file a this xml file i want to parse in other class. Now I have prepare thread, where I can download it. In MainForm I'm using WaitForSingleObject, but this function freeze MainFrom, so how can I prevent reezing and wait for value? Thanks.

Was it helpful?

Solution

First, design your thread with events and invoke them using Synchronize.

Create thread in MainForm and assign event handlers to it:

Thread := TMyThread.Create(True);
Thread.OnDownload := DoDownload;
Thread.OnParse := DoParse;
// Other Events
Thread.Start;

You should not WaitFor* in MainForm. Avoid Windows messages method because your app will loose platform portability, just linked to WinXX compilation.

OTHER TIPS

It's not really a good design to wait on the main thread, but in some cases it can be necessary. However, while you wait, you still need to process messages coming to the thread.

Take a look at MsgWaitForMultipleObjects at MSDN.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top