WARNING!!! Deadlocks when using Task.WaitAll and async methods.
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Sun, 15 Jun 2014 17:45:51 +0000 (19:45 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Sun, 15 Jun 2014 17:45:51 +0000 (19:45 +0200)
Allgemeines/HttpClientsExamples/HttpClientsExamples/HttpClientExample.cs
Allgemeines/HttpClientsExamples/HttpClientsExamples/HttpWebRequestExample.cs
Allgemeines/HttpClientsExamples/HttpClientsExamples/WebClientExample.cs
Allgemeines/ProcessLauncher/ProcessLauncher/LocalizedResourceManager.cs [new file with mode: 0644]

index f1a6a84..ca8ecc9 100644 (file)
@@ -40,6 +40,13 @@ namespace HttpClientsExamples
                 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 => {
@@ -69,6 +76,13 @@ namespace HttpClientsExamples
                             // 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 => {
@@ -119,6 +133,13 @@ namespace HttpClientsExamples
             }
             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 => {
@@ -153,6 +174,13 @@ namespace HttpClientsExamples
             }
             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 => {
@@ -213,7 +241,7 @@ namespace HttpClientsExamples
             }
         }
 
-        async private Task<string> ReadResponseAsync(HttpContent content)
+        private async Task<string> ReadResponseAsync(HttpContent content)
         {
             /**
              * Taken from HttpContent.cs ReadAsStringAsync() Mono implementation.
index 1421679..3716155 100644 (file)
@@ -64,6 +64,13 @@ namespace HttpClientsExamples
             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 => {
index a7d10ed..1d99623 100644 (file)
@@ -173,6 +173,13 @@ namespace HttpClientsExamples
                 // 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 => {
diff --git a/Allgemeines/ProcessLauncher/ProcessLauncher/LocalizedResourceManager.cs b/Allgemeines/ProcessLauncher/ProcessLauncher/LocalizedResourceManager.cs
new file mode 100644 (file)
index 0000000..b3c77bc
--- /dev/null
@@ -0,0 +1,12 @@
+using System;
+
+namespace ProcessLauncher
+{
+    public class LocalizedResourceManager
+    {
+        public LocalizedResourceManager()
+        {
+        }
+    }
+}
+