Solved

16-bit App hogging CPU

Posted on 2002-04-26
6
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

740 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