   100% CPU usage on DirectX render loop code.
  I recently read a few articles on how to design a better RenderLoop for DirectX applications, and I came accross this article...Tom Miller's Render LoopI decided to test it out with the code below...using System;using Microsoft.DirectX;using Microsoft.DirectX.Direct3D;using System.Windows.Forms;using System.Runtime.InteropServices;public class cMain{    #region "Native API Calls"    [StructLayout(LayoutKind.Sequential)]    public struct PeekMsg {  public IntPtr hWnd;  public Message msg;  public IntPtr wParam;  public IntPtr lParam;  public uint time;  public System.Drawing.Point p;    }    [DllImport("User32.dll", CharSet=CharSet.Auto)]    private static extern bool PeekMessage(out PeekMsg msg, IntPtr hWnd,uint messageFilterMin, uint messageFilterMax, uint flags);#endregion    MyWindow MyDisplay = new MyWindow();    static void Main()    {   cMain MyProgram = new cMain();   MyProgram.sMainLoop();    }    public void sMainLoop()    {   /* Hook the events tied with the window. */   System.Windows.Forms.Application.Idle += new EventHandler(OnApplicationIdle);   System.Windows.Forms.Application.Run(MyDisplay);    }    /* While the CPU isn't out helping other programs, use it to power this one. */    private void OnApplicationIdle(object sender, EventArgs e)    {   while (AppStillIdle())   {   // Render a frame during idle time (no messages are waiting)   //UpdateEnvironment();   //Render3DEnvironment();   }    }    /* Checks whether any messages are going through the desktop. */    private bool AppStillIdle()    {   PeekMsg msg;   return !PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);    }}... and it worked quite nicely, with the exception of course that I noticed it was using 100% of my CPU. Is it suppose to be using 100% or did I make a boo-boo in my code?   
  I dont see a sleep - so your app will never give up any cycles   ;Quote:Original post by incinI dont see a sleep - so your app will never give up any cyclesAn Application.DoEvents() also gives up cycles, but thats not present either. =/;  Why would it not use 100% CPU? It should be rendering as many frames as possible.   ;  This is a very common question - you should do a forum search.  Basically do not worry about it.   ;  What is your goal?What is the scenario that you are trying to address?The loop should work as advertisedWhile you are not interacting with your application it will use all the CPU possible, if you are interacting with the application it will prioritize windows messages over the game loop.In this case your application should be responsive if you try to drag it ir passing the mouse over it.  But if nothing else is going on it will use all the CPU.What behavior are you seeing?   