0

Please help me out with this, when running nothing is displayed

class Program
{
    public static void Write(string input, int times)
    {
        int i = 1000;
        while (i-- > 0)
        {
            Console.WriteLine($"{input}  {i}");
        }
    }

    static void Main(string[] args)
    {
        Task.Factory.StartNew(() => Write("ABC", 10));
    }
}
3
  • you aren't waiting for the tasks to complete. Mar 2, 2020 at 20:56
  • What is the purpose of times in your method? It appears to be ignored. Mar 2, 2020 at 21:18
  • I don't understand why this question was closed as needing more focus; it describes a clear problem that is not obvious. Mar 3, 2020 at 16:00

1 Answer 1

4

A C# console program ends when control leaves Main. You said to start a worker to run a task and then control left Main before the worker actually ran. Workers do not keep a program alive; they are killed when the main thread is done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.