RE: CPU performance rises when I'm opening an other application/dialog
- From: "Michael Schwab" <MichaelSchwab@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 15 May 2005 08:39:36 -0700
Goodness those other "answers" were about as half baked as you can get. I've
seen the exact same problem you're experiencing and have a templated solution
I use on each app now. Consider the following game loop...
while (form.Created)
{
if (form.WindowState != FormWindowState.Minimized)
{
//Update our game, and render to screen
form.Render();
Thread.Sleep(1);
}
else
{
Thread.Sleep(300);
}
Application.DoEvents(); //Let the OS handle what it needs to
}
form is my directx window. form.Render() calls a bunch of objects that know
how to render themselves. The interseting part is the Thread.Sleep(1) line.
This little sleep period causes the app to release system resources and cut
my "background mode" cpu utililization from +80% to < 1%. In a real app.
You'd likely have a variable whose value changes based on the actual render
time of your app, this would become your fps lock if you wanted to lock your
fps to 60fps or whatever. Either way, without the sleep, you're app will run
as fast as possible and utilize as much cpu as is available (why this only
happens when the app is in background mode, is still a mystery to me).
"Wilfried Hafner" wrote:
> Hi!
>
> My application with a direct3d device needs only about 01 - 02% of
> cpu performance, but if I call a dialoge from the same application
> the cpu performance rises up to 50%.
> This happens also, when I'm opening an other application like
> fireworks or something at the same time...
> I'm rendering the Data in the OnPaint - Event...
>
> Thanks Willi
>
.
- Follow-Ups:
- Re: CPU performance rises when I'm opening an other application/dialog
- From: Robert Dunlop [MS MVP]
- Re: CPU performance rises when I'm opening an other application/dialog
- References:
- CPU performance rises when I'm opening an other application/dialog
- From: Wilfried Hafner
- CPU performance rises when I'm opening an other application/dialog
- Prev by Date: Surface is deprecated
- Next by Date: Sprite.Draw draws differently on different computers
- Previous by thread: Re: CPU performance rises when I'm opening an other application/dialog
- Next by thread: Re: CPU performance rises when I'm opening an other application/dialog
- Index(es):
Relevant Pages
|