Home » U++ Library support » U++ MT-multithreading and servers » How to update main thread UI when runing other thread
How to update main thread UI when runing other thread [message #24964] |
Sat, 06 February 2010 10:17  |
jiuzhi
Messages: 10 Registered: October 2009
|
Promising Member |
|
|
Thread work;
engine->working(true);
work.Run(callback(engine,&hEngine::getData));//-getData will do some UI refresh;
while (engine->working()){
Refresh();//It cann't update UI here;
Sleep(100);
}
I have thought of a solution is packaged into a function, and create a new Thread to run it;But it is too cumbersome.
In MFC,I can use PeekMessage;
In delphi,I can use Application.ProcessMessage;
Is there a similar solution in u++?
[Updated on: Sat, 06 February 2010 10:21] Report message to a moderator
|
|
|
Re: How to update main thread UI when runing other thread [message #24965 is a reply to message #24964] |
Sat, 06 February 2010 11:32   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
jiuzhi wrote on Sat, 06 February 2010 04:17 |
Thread work;
engine->working(true);
work.Run(callback(engine,&hEngine::getData));//-getData will do some UI refresh;
while (engine->working()){
Refresh();//It cann't update UI here;
Sleep(100);
}
I have thought of a solution is packaged into a function, and create a new Thread to run it;But it is too cumbersome.
In MFC,I can use PeekMessage;
In delphi,I can use Application.ProcessMessage;
Is there a similar solution in u++?
|
I am not quite sure what the problem is. However, here are several hints:
First, in U++, only main thread does GUI.
PostCallback - any thread can post a callback that gets executed in the main thread
GuiLock - any thread can access GUI objects directly
Ctrl::Call - you can even "call" routines in the main thread. This is done by placing callback to the queue and waiting until it gets processed by the main thread. In fact, most calls to Ctrl routines, like performing message loop, automatically redirect to the main thread using this Call (or similiar ICall).
Please check these examples:
reference/GuiLock
reference/GuiMT
|
|
|
Re: How to update main thread UI when runing other thread [message #24969 is a reply to message #24964] |
Sat, 06 February 2010 14:04   |
jiuzhi
Messages: 10 Registered: October 2009
|
Promising Member |
|
|
I take a look at GuiMT. But it isn't what I want.In GuiMT,it create a task thread,But it does not need to wait for returned results
What I mean is waiting a task thread do a task and return result to main thread block;
The task thread use GuiLock to refresh UI.But under U++,when main thread waiting,the task thread call Ctrl::Refresh look does not work.
In U++,I can only find a way to do this job,create task thread,and then create a waiting thread.It is cumbersome.
I cann't write code to be waiting in the main thread,otherwise the task thread cann't refresh UI.
in delphi, only main thread does GUI too.But it can do this job in the main thread.
begin ///this block run in the main thread
create and run task thread......
create and run task thread......
Application.processmessage;///refresh UI immediately. In U++,it does not work.
create and run task thread......
create and run task thread......
do some job......
end
OR:
begin ///this block run in the main thread
create and run task thread......
create and run task thread......
while not result do begin ///wait the task thread result and refresh UI. In U++, this will lock the GUI,other threads try to refresh the interface does not work
sleep(100);
Application.processmessage;///In delphi,this code is used to process GUI message in the main thread
end;
do some job......
end
What I would like to know is the routine which does the same function in U++ like Application.Processmessage in delphi?
[Updated on: Sat, 06 February 2010 14:13] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 08:30:19 CEST 2025
Total time taken to generate the page: 0.01125 seconds
|