Skip to content

Commit bb569a1

Browse files
committed
Matt's latest revision
1 parent 66e4453 commit bb569a1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

_posts/2012-04-19-show-and-tell-mabster.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ I decided to use good ol' `System.Net.WebRequest` when making my calls to Twitte
6565

6666
That returns a running Task which is performing the request and will return the response in the `Result` property.
6767

68+
Budgie, however, doesn't use it. Why? Because I wanted all HTTP requests in Budgie to honour a Timeout property, and WebRequest doesn't honour its own Timeout property unless you use the synchronous `GetResponse` method. So my code actually looks like this:
69+
70+
return Task.Factory.StartNew(() => request.GetResponse());
71+
72+
It could be argued that that's actually _more_ readable. :)
73+
6874
From there I can use a continuation (since Budgie is written using C# 4 and doesn't make use of the "await" keyword) to take action when the task completes:
6975

7076
return requestTask.ContinueWith(t =>
@@ -84,4 +90,4 @@ All in all, it's pretty easy! Easier still had I written this code with C# 5, bu
8490

8591
## Wrapping Up
8692

87-
Using the TPL to create an asynchronous API is the logical choice in modern .NET development, and I wouldn't have done anything different in Budgie. I'm looking forward to the final release of VS11 and .NET 4.5, at which point I'll refactor the code to make use of the "await" keyword, but for now it's good to know that you can do this in a future-proof way with the current tools.
93+
Using the TPL to create an asynchronous API is the logical choice in modern .NET development, and I wouldn't have done anything different in Budgie. I'm looking forward to the final release of VS11 and .NET 4.5, at which point I'll refactor the code to make use of the "await" keyword, but for now it's good to know that you can do this in a future-proof way with the current tools.

0 commit comments

Comments
 (0)