CPU Usage

Posted on 2004-11-04
Last Modified: 2010-04-05

My application runs with 100% CPU usage!!!!

I have no iterative calculations.
I do however use dll and write to xml files (using clientdatasets).

Anything I should watch out for?

Question by:VEEPROG
    LVL 2

    Expert Comment

    Try to insert Application.Processmessages; to your code.

    LVL 4

    Expert Comment

    Or when you have a Thread running with some kind of internal loop, insert sleep(10) to trim down the cpu usage...

    LVL 17

    Expert Comment

    by:Wim ten Brink
    Use of Sleep(0) is as effective as Sleep(10) since both commands will pass processor time to another thread...

    There could be code in the DLL that needs this much processor time.
    It could also be that your XML file is quite huge, thus Windows has to do some memory swapping and other stuff to write it all to file.

    One thing you could try is to increase or decrease the thread and process priority of your application. If you increase it, it will run faster and this it will finish faster too. But it might starve some other processes and threads of their processing time. If you lower it, your application will slow down but it might also take less processor time that way.
    LVL 7

    Expert Comment

    You could also try giving you program a lower importance

    SetPriorityClass( GetCurrentProcess,HIGH_PRIORITY_CLASS);

    this question shows how to do it

    LVL 5

    Expert Comment

    Watch out for the deadly infinite loops. Any loops that are not cancelling (ending) will quickly chew up usage. 100% CPU usage is a sure sign of some loop calculation that cannot end properly. Check the terminating conditions to be sure loops can terminate eventually.


    LVL 17

    Expert Comment

    by:Wim ten Brink
    The problem could be related to the ClientDatafiles and the generation of those XML files. Especially if you have a huge amount of data. This is because the ClientDataset will try and load it all, start swapping memory if RAM runs out which could happen quite fast and then it might have to process it's data to write it back to file again. Especially if data is converted from XML to binary and back again, you could eat up lots of CPU cycles. Which is why it might help to alter the priority of the thread or process. A higher priority will make it eat more CPU, but it will finish faster. A lower priority will slow it down but less CPU will be eaten. It depends on the actual situation.

    Accepted Solution

    PAQed with no points refunded (of 300)

    Community Support Moderator

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    755 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

    18 Experts available now in Live!

    Get 1:1 Help Now