Solved

16-bit App hogging CPU

Posted on 2002-04-26
6
259 Views
Last Modified: 2010-05-18
I have a 16-bit Windows app that is hogging all the CPU. It is written and compiled in MCVC++ Ver 1.5. The problem is commming from the message loop in the WinMain function. What could I change inorder to do something like Sleep(1) which is not valid. Here is the code below.

Thanks in advance.

while (TRUE)
  {
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
      if (msg.message == WM_QUIT)
         break;
      else
      {
        if(!TranslateAccelerator(hwndSaint,hAccTable,&msg))
        {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
      }
    }
    else
    {
      // If not an internal XOFF and communications is still active,
      //     get the next available input.
     
      if(!flags.pause)
      {
        ret = (*channel.input)();
        if(ret < 0)
          SetNullComm(FALSE);
      }
    }    
  }
0
Comment
Question by:jsaxon2
  • 2
  • 2
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 6972347
Hmm, that's a while ago, but I remember there was a'Yield()' function in Win16 for that...
0
 
LVL 3

Author Comment

by:jsaxon2
ID: 6972365
Yield is not working. The CPU usage is still at 99%. It is also causing other problems. Any other ideas.

I have to apologize. I did not write this app. It was written about a long time ago by a person who is no longer with our company.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6972375
So what does this matter?  There is nothing wrong with the CPU running at 99%.  The only thing that is not running is the SYSTEM IDLE process.  

Big deal.  Your 16-bit app is keeping your CPU from doing nothing!
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 32

Expert Comment

by:jhance
ID: 6972376
Oh, the fix for this is to stop running the TASK MANAGER.
0
 
LVL 3

Author Comment

by:jsaxon2
ID: 6985829
I found the answer myself. I changed the function as follows.

while(GetMessage(&msg, NULL, 0, 0))
 {

      if (msg.message == WM_QUIT)
         break;
      else
      {
        if(!TranslateAccelerator(hInstance,hAccTable,&msg))
        {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
      }
      // If not an internal XOFF and communications is still active,
      //     get the next available input.
      if(!flags.pause)
      {
        ret = (*channel.input)();
        if(ret < 0)
          SetNullComm(FALSE);
      }
 }


I'll award the points to jkr, because he at least tried to help. Thanks jkr.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6987644
Thank you!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question