?
Solved

16-bit App hogging CPU

Posted on 2002-04-26
6
Medium Priority
?
267 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 300 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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.
Suggested Courses

649 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