DEV Community

Discussion on: What coding concept or practice seem commonly understood, but you never learned?

Collapse
 
bugmagnet profile image
Bruce Axtens

Today it hit me hard that I still haven't quite got my head around async/await and Tasks in C#. With 3rd party libraries all going the async direction, I'm getting even more behind than I usually am.

Collapse
 
tinussmit profile image
Tinus Smit

Same here. They always say it's as simple as adding async / await in your method, but I always seem to get stuck at a method that just has no logical async-ness to it. Then, do I just add an

await Task.Delay(100);

to make it async just for the sake of it?

Collapse
 
bugmagnet profile image
Bruce Axtens • Edited

How about this?

           Task task = GoogleWebAuthorizationBroker.ReauthorizeAsync(
                userCredential,
                CancellationToken.None
            );
            task.Wait();
Enter fullscreen mode Exit fullscreen mode

which seems to be how to make an async Task act in a sync way(???) The Wait appears to mean "wait (that is 'block') until the Task has finished."