<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WebClientExample.cs" />
+ <Compile Include="HttpWebRequestExample.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
* DO NOT BOTHER DISPOSING OF YOUR TASKS: http://blogs.msdn.com/b/pfxteam/archive/2012/03/25/10287435.aspx
*/
Task<Stream> task = client.OpenReadTaskAsync (line);
- task.Start ();
+ // Don't do this. OpenReadTaskAsync is already launching a new Thread (OpenReadTaskAsync is intended to be used with async/await)
+ //task.Start ();
try {
Task.WaitAll (task);
} catch (AggregateException ae) {
}
});
}
- // I am starting to love the using statement instead of traditional try/finally block with check for null values and close.
- using (Stream replyStream = task.Result)
- using (StreamReader replyStreamReader = new StreamReader (replyStream))
+ if (task.Status == TaskStatus.RanToCompletion)
{
- string s = replyStreamReader.ReadToEnd ();
- Console.WriteLine (s);
+ // I am starting to love the using statement instead of traditional try/finally block with check for null values and close.
+ using (Stream replyStream = task.Result)
+ using (StreamReader replyStreamReader = new StreamReader (replyStream))
+ {
+ string s = replyStreamReader.ReadToEnd ();
+ Console.WriteLine (s);
+ }
}
}
}