   C# Main game loop
  What's the easiest way to set up a main game loop in C#? I'm wanting to set up a game loop that doesn't block on windows messages, and I'm not sure how to do so.EDIT: Fixed title.[edited by - Muzlack on February 13, 2004 2:10:53 PM]
  Well, i don''t know C#, but some pseudocode might help while(!done){if(ThereIsAMessageWaiting)//PeekMessage{Process messages()//TranslateMessage,PeekMessage}else{Game Loop()}if(msg.message = WM_QUIT)done = true;};  << What''s the easiest way to set up a main game loop in C#? >>Hey I got a small complaint. People should type full subject lines. Instead ofEasiest way to.....Be more explicit. Type as subject: Main Game Loop in C#Since that''s what the subject is. Then I know what the darn thread is about. The elipses --> .... reminds me of the Email spam that tries to get you to open it with an enticing .....  People are so used to seeing those in spam Emails now they use that strategy in GameDev subject lines. And it worked since "Easiest way to....." made me check what you were talking about. But I won''t fall for it again! So in conclusion people: don''t be lazy, be more expressive in your subject lines. Type the whole darn "Main Game Loop in C#" without the mysterious ellipses "Easiest way to....."Don''t know C#, so I can''t help much with the subject. But for the occasional uber newbie, you can get away with 1 or 2 mysterious and enticing "Hey, what was the....." as the subject...........................Phil P......................?????? ;  Sorry for the confusing title. At any rate, yes, that code works in C, however I''m not quite sure how to translate this to C# .NET. I recently got .NET, and I''m new to the whole new architecture (not to mention programming language in this case) . ;  How about this article ?Easy to find with google.Anyway, these pages just use one file with everything in the same class that holds main(). I'd rather separate it and put all directx stuff in a second file, so that the main cs file doesn't even need to use "using namespace Microsoft.DirectX" using System.Drawing; using System.Windows.Forms; namespace Myname.demo001{   public class App: System.Windows.Forms.Form   {static void Main(){  App myapp = new App(); Game mygame = new Game(); Game.InitializeGraphics(app);  myapp.Show();  while (myapp.Created)  {    System.Threading.Thread.Sleep(1);   Game.Render();    Application.DoEvents();  }  Game.DisposeGraphics();}   } }Your second file, game.cs would then have the class definition for the Game class that does everything with the device.The InitializeGraphics would look like:   public bool InitializeGraphics (Project1.WinForm form)  {    pres.Windowed = true;    pres.BackBufferCount = 1;    pres.SwapEffect = SwapEffect.Discard ;    // Tell Direct3D to create a ZBuffer for us    pres.EnableAutoDepthStencil = true ;    pres.AutoDepthStencilFormat = DepthFormat.D16;    device = new Device(0, DeviceType.Hardware, form, CreateFlags.SoftwareVertexProcessing, pres);... etcI keep the private PresentParameters pres = new PresentParameters ();  as private variable of the Game class, not local inside InitializeGraphics because you'd need it later on when you reset the device in case the user resizes the window or goes to fullscreen.[edited by - fidelio66 on February 13, 2004 4:16:28 PM]