Click to See Complete Forum and Search --> : Program slows down when is minimized!
Mirsad
May 24th, 2006, 02:55 AM
Hello,
i have an problem with my Program when is minimized or the dialog lost focus,
when i select an other window, program execution stops or slows down, to much!
What can be an problem???
CWinThread
Naumaan
May 24th, 2006, 05:50 AM
What kind of program u have and whats the architectue/Design of such app. Can u provide more details and poste some code here to review.
philkr
May 24th, 2006, 06:59 AM
Windows always gives a little more cpu time to the thread of the currently active window.
There are 31 priority levels. When your app is in the foregroud you have priority 9, when it is in the background it only has 7. You have to adjust the thread priority level, if you want to have always priority of 9:
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_HIGHEST); // level 9 priority
::SetThreadPriorityBoost(::GetCurrentThread(), TRUE); // disables dynamic boosting
Mirsad
May 24th, 2006, 07:53 AM
Hello,
it's an Dialog based Application on WindowsXP Prof., and the Threads started like this:
[c++]
CWinThread* cCurrThread = AfxBeginThread(ThreadFunc,pThreadParams,THREAD_PRIORITY_HIGHEST);
lThreadCount++;
if (NULL == cCurrThread )
{
AfxMessageBox(L"Error, thread is not created!");
lThreadCount--;
return 0;
}
[/c++]
So i try to use with ::SetThreadPriorityBoost(::GetCurrentThread(), TRUE);
this helps maybe!
thanx for answers!
mirsad
philkr
May 24th, 2006, 08:43 AM
If you already created the thread with THREAD_PRIORITY_HIGHEST you are on priority level 11. So you should use priority class ABOVE_NORMAL_PRIORITY_CLASS and thread priority THREAD_PRIORITY_ABOVE_NORMAL to achieve the same level for background window.
Arjay
May 24th, 2006, 12:32 PM
I disagree with changing the thread priority in a UI thread. If you set the priority of the UI thread to anything other than normal, you will impact the responsiveness of the UI across other applications in the system - definitely not something you want.
You should probably revisit the design of the application and put all UI components into the main thread and the file manipulation stuff into non-UI worker threads. For the non-UI threads that don't use MFC, prefer _beginthreadex to create the worker thread. You can change the thread priority in these threads as appropriate, but keep in mind worker threads should perform work in small chunks; otherwise they will starve out lower priority threads (like the UI threads across the system).
I'm not really clear if the worker threads you are creating are UI threads however. Based, on the fact that you are seeing a slowdown when the app is minimized, I suspect that they are UI threads. With regard to boosting of priority that philkr mentioned, I don't believe this applies to non-UI worker threads. To be sure, open your application and use Spy to view the windows (attached to threads) for your application. If you see windows attached to any non-UI threads, you'll know the 'worker' threads are really UI threads (and therefore are impacted by minimizing the application).
Mirsad
June 8th, 2006, 02:58 AM
Hello,
i solve my problem with threads, i have a Messageloop in my thread function
with AfxGetThread->PumpMessage(); coded, and after i remove this
program run normal, even when is minimized!
regards
mirsad
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.