Simple enough question, I just need to break through one minimal wall of confusion.
So based on the simple code below:
Task task1 = new Task(() =>
{
for (int i = 0; i < 500; i++)
{
Console.WriteLine("X");
}
});
task1.Start();
task1.Wait();
for (int j = 0; j < 500; j++)
{
Console.WriteLine("Y");
}
Console.ReadLine();
So based on the above, will the Task be on its own separate thread and the other code on the main thread?
Now in terms of wait, I'm confused as to what I am instructing to wait. So going back to the above example, let's say now Task 1 has an insane amount of work to do and in the main thread only exists a single statement like below:
Task task1 = new Task(() => { //insane amount of work to do which might take a while }); task1.Start(); task1.Wait(); Console.WriteLine("HI");
Console.ReadLine();
Is the Wait just blocking the thread Task1 is on? If so, shouldn't that allow the other thread (the main thread) with the WriteLine statement to execute before task1 is complete? Or is the wait saying "No threads shall run until I am done"?