Dragon4ik
Member
- Joined
- Oct 24, 2020
- Messages
- 16
- Programming Experience
- Beginner
I'm bad in async programming, so tried to make a simple program, which should consolidate my knowledge. But when I compile code, nothing happen
Here is my code:
I tried debugging, but process stops on this line:
Please, can you help and explain , what I do wrongly?
P.S. Thank you in advance
Here is my code:
C#:
static void Main(string[] args)
{
int x,y;
x = y = 0;
string str = "abcd";
ASyncGet(x,y,str);
}
static async void ASyncGet(int i1,int i2, string str)
{
Task t1 = Task.Run(()=>Get1(str));
Task t2 = Task.Run(() => Get2(str));
await Task.WhenAll(t1, t2);
}
static int Get(string str)
{
int i = 0;
for (int j = 0; j < str.Length; j++)
{
i++;
Console.WriteLine(str[j]);
}
return i;
}
static async Task<int> Get1(string str)
{
return await Task.Run(() =>Get(str));
}
static async Task<int> Get2(string str)
{
return await Task.Run(() => Get(str));
}
I tried debugging, but process stops on this line:
C#:
await Task.WhenAll(t1, t2);
Please, can you help and explain , what I do wrongly?
P.S. Thank you in advance
Last edited: