-2

This is my code :

  class Program
{
    static void Main(string[] args)
    {
        update();
    }

    static async void update()
    {
        await Task.Delay(100);
        Console.WriteLine("X");
        update();
    }
}

Console never outputs any text at all, and I have no clue why. What am I doing wrong?

2

1 Answer 1

1

Your Main method is not async, so it doesn't wait for your update method. Also, your update method should return a Task so your Main method can await it.

static async Task Main(string[] args)
{
    await update();
}

static async Task update()
{
    await Task.Delay(100);
    Console.WriteLine("X");
    await update();
}
Sign up to request clarification or add additional context in comments.

2 Comments

@Selvin Thanks I'll update the answer
Would that not cause an stack overflow?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.