Solved

16-bit App hogging CPU

Posted on 2002-04-26
6
255 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now