Delay a single method for snake game c#
<p>I am using SwinGame to develop a snake game. The method MoveForward handles the movement of the snake. The problem that I have now is that i am unable to delay that particular method so that the snake will be moving at a constant slow speed. </p>

<p>Here are the codes in the Main:</p>

<pre><code>using System;
using SwinGameSDK;
using System.Threading.Tasks;


namespace MyGame
{
    public class GameMain
    {

    public static void Main ()
    {

        //Open the game window
        SwinGame.OpenGraphicsWindow ("GameMain", 800, 600);
        SwinGame.ShowSwinGameSplashScreen ();

        Snake snake = new Snake ();


        //Run the game loop
        while (false == SwinGame.WindowCloseRequested ()) {
            //Fetch the next batch of UI interaction
            SwinGame.ProcessEvents ();

            //Clear the screen and draw the framerate
            SwinGame.ClearScreen (Color.White);

            SwinGame.DrawFramerate (0, 0);

            // Has to go after ClearScreen and NOT before refreshscreen

            snake.Draw ();

            Task.Delay (1000).ContinueWith (t =&gt; snake.MoveForward ());


            snake.HandleSnakeInput ();

            //Draw onto the screen
            SwinGame.RefreshScreen (60);


        }
    }
}
}
</code></pre>

<p>As you can see from the codes, the game runs on a while loop. I was able to delay the method using "Task.Delay (1000).ContinueWith (t => snake.MoveForward ());" but only on the first loop. When i debug, the snake delays successfully on the first loop but zoom pasts the rest of the loops. </p>

<p>How can i implement the code so that at every loop the method is delayed so that the snake can move at a constant speed?</p>

<p>Thanks in advance.</p>