Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Maybe it is a stupid question.
C#
class Program
   {
       static void Main(string[] args)
       {
           Task t = new Task(() =>
           {
               int i = 0;
               for (i = 0; i < 100; i++)
               {
                   Console.WriteLine("*");
               }
           });
           t.Wait();
       }
   }

Why it didn't print?
Posted

1 solution

You wait for the task to be finished, but you never start the task. Use t.Start() to do that:
C#
// code to define task here

t.Start();
t.Wait();
 
Share this answer
 
Comments
[no name] 2-Jan-15 10:51am    
Thanks, it is my fault. It was a typo, the book used Task.Run and I overlooked it.
Sergey Alexandrovich Kryukov 2-Jan-15 19:36pm    
Not only a typo. I would strongly recommend to write code with your own hands, using your knowledge you get from documentation and theoretical books. Not to copy a code sample and tweak it. Slower way is faster. :-)
—SA
Sergey Alexandrovich Kryukov 2-Jan-15 19:34pm    
Sure, a 5.
—SA
Thomas Daniels 3-Jan-15 4:09am    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900