From cdadec93c07c439abb1fe73edd055d04e28272e6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Laval?= Date: Mon, 14 Feb 2011 17:58:38 +0000 Subject: [PATCH] Don't create a new lambda everytime when queuing Task via ThreadPool QueueUserWorkItem --- mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs b/mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs index 6b94fcddb67..d6e2b0a459e 100644 --- a/mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs +++ b/mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs @@ -42,7 +42,15 @@ namespace System.Threading.Tasks public void AddWork (Task t) { - ThreadPool.QueueUserWorkItem (_ => t.Execute (null)); + ThreadPool.QueueUserWorkItem (TaskExecuterCallback, t); + } + + static void TaskExecuterCallback (object obj) + { + Task task = obj as Task; + if (task == null) + return; + task.Execute (null); } public void ParticipateUntil (Task task) -- 2.11.4.GIT