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.

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top