when I was playing with tasks on C#, I was wondering what's the difference between using GetAwaiter().OnCompleted() and callbacks
Case 1 : task1.GetAwaiter().OnCompleted()
Task task1 = new Task(() =>
{
//Do Work_1 here
});
task1.GetAwaiter().OnCompleted(() =>
{
//Do something here where Work_1 Completed
});
task1.Start();
Case 2 : CallBack
await Task2(() =>
{
//CallBack
});
private async Task Task2(Action callBack)
{
//do Work_2 here
await Task.Run(callBack);
}
I want to understand this and I think I'm missing something.
GetAwaiter()
method: This method is intended for compiler user rather than use directly in code. – Carrell