Skip to content

Instantly share code, notes, and snippets.

@tophyr
Created March 3, 2014 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tophyr/9336450 to your computer and use it in GitHub Desktop.
Save tophyr/9336450 to your computer and use it in GitHub Desktop.
public void DoStuff()
{
SendData("https://blah", "blah").ContinueWith(task => DoEvenMoreStuff());
}
private async Task SendData(string url, string data)
{
WebRequest req = WebRequest.Create(url);
using (StreamWriter writer = new StreamWriter(await req.GetRequestStreamAsync())) // why await here?
{
writer.Write(data);
writer.Close();
}
WebResponse resp = await req.GetResponseAsync(); // or here? we're already executing in the ThreadPool.
DoOtherStuff(resp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment