Solved

16-bit App hogging CPU

Posted on 2002-04-26
6
261 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 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