Skip to content

Instantly share code, notes, and snippets.

@M-Yankov
Created October 27, 2017 14:12
Show Gist options
  • Save M-Yankov/7205bf42cbedcb05cfd6eeef0289cff4 to your computer and use it in GitHub Desktop.
Save M-Yankov/7205bf42cbedcb05cfd6eeef0289cff4 to your computer and use it in GitHub Desktop.
Returns a result from Task
string text = System.Threading.Tasks.Task.Run(() => "TEXT".ToLower()).GetAwaiter().GetResult();
// To retreive the result it bloks the other code.
// https://www.youtube.com/watch?v=fX62PJ_wv20
@M-Yankov
Copy link
Author

M-Yankov commented May 3, 2018

/* How to not block UI thread: */
public static void Main()
{
   Task exitTask = ExitCommandAsync();
   Task.WaitAll(exitTask);
}

private static Task ExitCommandAsync()
{
    return Task.Run(() =>
    {
         while (Console.ReadLine() != ExitCommand)
         {
         }
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment