Answers for "async await vs synchronous c#"

C#
1

async await vs synchronous c#

Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");
string urlContents = await getStringTask;
      
                 VS
string urlContents = await client.GetStringAsync();

Answer:
Calling await client.GetStringAsync() yields the execution to the calling method,
which means it won't wait for the method to finish executing,
and thus won't block the thread. Once it's done executing in the background,
the method will continue from where it stopped.

If you just call client.GetString(), the thread's execution won't continue
until this method finished executing,
which will block the thread and may cause the UI to become unresponsive.
Posted by: Guest on December-11-2020

C# Answers by Framework

Browse Popular Code Answers by Language