Task<HttpResponseMessage> task =
client.GetAsync (uri, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
try {
+ // DO NOT DO THIS. THERE COULD BE DEADLOCK. ALL DEPENDS ON THE SynchronizationContext
+ // How may I know what SynchronizationContext is going to be used? :/
+ // See: http://msdn.microsoft.com/en-us/magazine/gg598924.aspx
+ // http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
+ // http://stackoverflow.com/questions/22699048/why-does-task-waitall-not-block-or-cause-a-deadlock-here
+ // AFAIK, I SHOULD USE Task.WhenAll INSTEAD!!!! Because it creates a task (a new thread instead of blocking the current one)
+ // http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.whenall%28v=vs.110%29.aspx
Task.WaitAll (task);
} catch (AggregateException ae) {
ae.Handle (e => {
// option I do not think content will be null.
Task<Stream> taskStream = content.ReadAsStreamAsync ();
try {
+ // DO NOT DO THIS. THERE COULD BE DEADLOCK. ALL DEPENDS ON THE SynchronizationContext
+ // How may I know what SynchronizationContext is going to be used? :/
+ // See: http://msdn.microsoft.com/en-us/magazine/gg598924.aspx
+ // http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
+ // http://stackoverflow.com/questions/22699048/why-does-task-waitall-not-block-or-cause-a-deadlock-here
+ // AFAIK, I SHOULD USE Task.WhenAll INSTEAD!!!! Because it creates a task (a new thread instead of blocking the current one)
+ // http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.whenall%28v=vs.110%29.aspx
Task.WaitAll (taskStream);
} catch (AggregateException ae) {
ae.Handle (e => {
}
Task<string> taskHttpClient = this.DoGetAsync (uri);
try {
+ // DO NOT DO THIS. THERE COULD BE DEADLOCK. ALL DEPENDS ON THE SynchronizationContext
+ // How may I know what SynchronizationContext is going to be used? :/
+ // See: http://msdn.microsoft.com/en-us/magazine/gg598924.aspx
+ // http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
+ // http://stackoverflow.com/questions/22699048/why-does-task-waitall-not-block-or-cause-a-deadlock-here
+ // AFAIK, I SHOULD USE Task.WhenAll INSTEAD!!!! Because it creates a task (a new thread instead of blocking the current one)
+ // http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.whenall%28v=vs.110%29.aspx
Task.WaitAll (taskHttpClient);
} catch (AggregateException ae) {
ae.Handle (e => {
}
taskHttpClient = this.DoGetStringAsync (uri);
try {
+ // DO NOT DO THIS. THERE COULD BE DEADLOCK. ALL DEPENDS ON THE SynchronizationContext
+ // How may I know what SynchronizationContext is going to be used? :/
+ // See: http://msdn.microsoft.com/en-us/magazine/gg598924.aspx
+ // http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
+ // http://stackoverflow.com/questions/22699048/why-does-task-waitall-not-block-or-cause-a-deadlock-here
+ // AFAIK, I SHOULD USE Task.WhenAll INSTEAD!!!! Because it creates a task (a new thread instead of blocking the current one)
+ // http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.whenall%28v=vs.110%29.aspx
Task.WaitAll (taskHttpClient);
} catch (AggregateException ae) {
ae.Handle (e => {
}
}
- async private Task<string> ReadResponseAsync(HttpContent content)
+ private async Task<string> ReadResponseAsync(HttpContent content)
{
/**
* Taken from HttpContent.cs ReadAsStringAsync() Mono implementation.
httpWebRequest = (HttpWebRequest) WebRequest.Create(uri);
Task<WebResponse> task = httpWebRequest.GetResponseAsync ();
try {
+ // DO NOT DO THIS. THERE COULD BE DEADLOCK. ALL DEPENDS ON THE SynchronizationContext
+ // How may I know what SynchronizationContext is going to be used? :/
+ // See: http://msdn.microsoft.com/en-us/magazine/gg598924.aspx
+ // http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
+ // http://stackoverflow.com/questions/22699048/why-does-task-waitall-not-block-or-cause-a-deadlock-here
+ // AFAIK, I SHOULD USE Task.WhenAll INSTEAD!!!! Because it creates a task (a new thread instead of blocking the current one)
+ // http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.whenall%28v=vs.110%29.aspx
Task.WaitAll (task);
} catch (AggregateException ae) {
ae.Handle (e => {
// Don't do this. OpenReadTaskAsync is already launching a new Thread (OpenReadTaskAsync is intended to be used with async/await)
//task.Start ();
try {
+ // DO NOT DO THIS. THERE COULD BE DEADLOCK. ALL DEPENDS ON THE SynchronizationContext
+ // How may I know what SynchronizationContext is going to be used? :/
+ // See: http://msdn.microsoft.com/en-us/magazine/gg598924.aspx
+ // http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
+ // http://stackoverflow.com/questions/22699048/why-does-task-waitall-not-block-or-cause-a-deadlock-here
+ // AFAIK, I SHOULD USE Task.WhenAll INSTEAD!!!! Because it creates a task (a new thread instead of blocking the current one)
+ // http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.whenall%28v=vs.110%29.aspx
Task.WaitAll (task);
} catch (AggregateException ae) {
ae.Handle (e => {