I tried out a few things with async/await but I dont't realy get it. All I want to achive for the beginning is to concurrently write to the Console from two different Threads. Here is the code:
static void Main(string[] args)
{
DoSomethingAsync();
for (int i = 0; i < 1000; i++)
Console.Write(".");
Console.ReadLine();
}
static async void DoSomethingAsync()
{
Console.WriteLine("DoSomethingAsync enter");
//This does not seem good
await Task.Delay(1);
for (int i = 0; i < 1000; i++)
Console.Write("X");
Console.WriteLine("DoSomethingAsync exit");
}
With Threads that was easy but with async/await I only get it done when I put in this strange
await Task.Delay(1);
Most basic examples I saw used this. But what to do, when you want to do something timetaking that is not async? You cant await anything and so all code runs on the main Thread. How can I achive the same behavior as with this code but without using Task.Delay()?
async void.