How to write a custom awaiter

[This post is part of a series How to await a storyboard, and other things]   The normal behavior of the “await” operator on a task is to suspend execution of the method; then, when the task operand has finished, to resume execution on the same SynchronizationContext and with the same ExecutionContext. You can replace the…

2

How to await a command-line process, and capture its output

[This post is part of a series How to await a storyboard, and other things]   I want to invoke an external executable, and await until it’s finished, and get back its output. (In my case, the external executable is called “tidy.exe” – an excellent open-source utility for turning HTML into clean parseable XML.) To cut a…

2

Await HttpClient.GetStringAsync() and cancellation

I’m a big fan of supporting cancellation on async methods. I was recently wondering how to do this for HttpClient.GetStringAsync(). This post has some answers.   Async Function TestAsync(uri As Uri, Optional cancel As CancellationToken = Nothing                         ) As Task(Of String)     Dim client As New HttpClient     Return Await client.GetStringAsync(uri, cancel)     ‘ error: no overload of GetStringAsync takes a cancellation…

5