From 50a295ac1becc5c0927917644a1b246b4c8e945b Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Thu, 30 Sep 2010 01:41:22 -0400 Subject: [PATCH] Invoke the callback in separate threads The callbacks need to be invoked in different threads to avoid clogging the IO pool. Fixes bug #639656. --- mcs/class/System/System.Net.Sockets/Socket_2_1.cs | 7 ++++++- mcs/class/System/System.Net/WebAsyncResult.cs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mcs/class/System/System.Net.Sockets/Socket_2_1.cs b/mcs/class/System/System.Net.Sockets/Socket_2_1.cs index a8b91e157ee..f937c9bfcd3 100644 --- a/mcs/class/System/System.Net.Sockets/Socket_2_1.cs +++ b/mcs/class/System/System.Net.Sockets/Socket_2_1.cs @@ -252,7 +252,12 @@ namespace System.Net.Sockets { } if (callback != null) - callback (this); + ThreadPool.QueueUserWorkItem (CB, null); + } + + void CB (object unused) + { + callback (this); } SocketAsyncCall GetDelegate (Worker worker, SocketOperation op) diff --git a/mcs/class/System/System.Net/WebAsyncResult.cs b/mcs/class/System/System.Net/WebAsyncResult.cs index 3c0a3154d47..a97c1da97ad 100644 --- a/mcs/class/System/System.Net/WebAsyncResult.cs +++ b/mcs/class/System/System.Net/WebAsyncResult.cs @@ -139,9 +139,14 @@ namespace System.Net { if (!callbackDone && cb != null) { callbackDone = true; - cb (this); + ThreadPool.QueueUserWorkItem (CB, null); } } + + void CB (object unused) + { + cb (this); + } internal void WaitUntilComplete () { -- GitLab