Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Thorsten Kettner
Thu, 19 Jul 2007 15:47
ProcessMessages / HandleMessage ???
Author: Thorsten Kettner
Date: Thu, 19 Jul 2007 15:47
Date: Thu, 19 Jul 2007 15:47
18 lines
1558 bytes
1558 bytes
Hi all, in my app there is a loop that takes a long time. So my app is busy and as Windows doesn't do multitasking very well, I must tell it to give time to the other apps, too, right? I was told to avoid a so-called tight loop by calling ProcessMessages every now and then. Is that the right way? Does it give time to other apps or just to my own message processing? Or must I use HandleMessage instead? Or something else? I would like my app to concentrate on its loop and do only this actually, I don't care much about my apps messages in that situation. But I want other apps to continue to run fast and not be infuenced much by my app being busy with its loop. So what is the right way to do this? Thanks for any hint. Thorsten.
Re: ProcessMessages / HandleMessage ???
Author: Remy Lebeau (TeamB)
Date: Thu, 19 Jul 2007 17:05
Date: Thu, 19 Jul 2007 17:05
33 lines
2215 bytes
2215 bytes
"Thorsten Kettner" <QUESTIONBYthorsten.kettner@otto.de> wrote in message news:469f87af$1@newsgroups.borland.com... > I must tell it to give time to the other apps, too, right? You must perform a yielding operation periodically that allows your app to give up the rest of its CPU timeslice so that other apps can have a chance to use the CPU. Something as simple as a call to Sleep() with a timeout between 0-10 ms will usually do the trick. > I was told to avoid a so-called tight loop by calling > ProcessMessages every now and then. Is that the right > way? Does it give time to other apps or just to my own > message processing? That depends on the amount of message traffic you have. If you have a lot of pending messages, then it may or may not yield right away. > I would like my app to concentrate on its loop and do only > this actually, I don't care much about my apps messages > in that situation. > I want other apps to continue to run fast and not be infuenced > much by my app being busy with its loop. So what is the right > way to do this? If you don't care about the messages, then use Sleep() in the loop. Otherwise, you should move the code into a worker thread and let the main thread handle its messages normally. Gambit
Re: ProcessMessages / HandleMessage ???
Author: Thorsten Kettner
Date: Fri, 20 Jul 2007 11:55
Date: Fri, 20 Jul 2007 11:55
34 lines
1802 bytes
1802 bytes
"Remy Lebeau \(TeamB\)" wrote:
>
>"Thorsten Kettner" wrote:
>> I must tell it to give time to the other apps, too, right?
>
>Something as simple as a call to Sleep() with a timeout
>between 0-10 ms will usually do the trick.
Gosh, how easy! I just didn't take Sleep into account at all! I
always though ProcessMessages had something to do with giving
time to other apps, too, and simply didn't see that this is for
my own app's processing only.
To be able to react on close I still use ProcessMessages and
have added Sleep now. Works perfectly!
for(int i = 0; i < end; ++i)
{
...
if(i % 100 == 0)
{
Application->ProcessMessages();
if(Application->Terminated)
{
break;
}
Sleep(1);
}
}
Thank you Remy.
Thorsten.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads