To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Other Languages > C and C++

Reply Post New Thread
 
Thread Tools Display Modes
Old Dec 23rd, 2003, 11:47 AM   #1
Chrissie
Lively Member
 
Join Date: Aug 02
Location: The Netherlands
Posts: 96
Chrissie is an unknown quantity at this point (<10)
Multitasking: restricting CPU usage

I'm currently working on a Multitasking Demo which comes from a Petzold book.

The app takes 99% of CPU usage, which makes it almost impossible to close it down, even causing system instability. Is it possible to restrict CPU usage?

Code:
LRESULT APIENTRY WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     static char   *szChildClass[] = { "Child1", "Child2",
                                       "Child3", "Child4" } ;
     static HWND    hwndChild[4] ;
     static WNDPROC ChildProc[] = { WndProc1, WndProc2,
                                    WndProc3, WndProc4 } ;
     HINSTANCE      hInstance ;
     int            i, cxClient, cyClient ;
     WNDCLASSEX     wndclass ;

     switch (iMsg)
          {
          case WM_CREATE :
               hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;

               wndclass.cbSize        = sizeof (wndclass) ;
               wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
               wndclass.cbClsExtra    = 0 ;
               wndclass.cbWndExtra    = 0 ;
               wndclass.hInstance     = hInstance ;
               wndclass.hIcon         = NULL ;
               wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
               wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
               wndclass.lpszMenuName  = NULL ;
               wndclass.hIconSm       = NULL ;

               for (i = 0 ; i < 4 ; i++)
                    {
                    wndclass.lpfnWndProc   = ChildProc[i] ;
                    wndclass.lpszClassName = szChildClass[i] ;

                    RegisterClassEx (&wndclass) ;

                    hwndChild[i] = CreateWindow (szChildClass[i], NULL,
                          WS_CHILDWINDOW | WS_BORDER | WS_VISIBLE,
                          0, 0, 0, 0, hwnd, (HMENU) i, hInstance, NULL) ;
                    }

               return 0 ;

          case WM_SIZE :
               cxClient = LOWORD (lParam) ;
               cyClient = HIWORD (lParam) ;

               for (i = 0 ; i < 4 ; i++)
                    MoveWindow (hwndChild[i], (i % 2) * cxClient / 2,
                                              (i > 1) * cyClient / 2,
                                cxClient / 2, cyClient / 2, TRUE) ;
               return 0 ;

          case WM_CHAR :
               if (wParam == '\x1B')
                    DestroyWindow (hwnd) ;

               return 0 ;

          case WM_DESTROY :
               PostQuitMessage (0) ;
               return 0 ;
          }
     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
     }
Chrissie is offline   Reply With Quote
Old Dec 23rd, 2003, 02:44 PM   #2
Kasracer
KrisSiegel.com
 
Kasracer's Avatar
 
Join Date: Jul 03
Location: USA, Maryland
Posts: 4,973
Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)
You could always make it low priority
Kasracer is offline   Reply With Quote
Reply

Go Back   VBForums > Other Languages > C and C++


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:14 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.