From 17482cb6c1b3c310162cf1399ca8e4ca7a899e0f Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 7 Jun 2014 12:40:33 +0200 Subject: [PATCH] Fixed: Processing more than 3 concurrent Automatic Searches should no longer freeze on mono. --- src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs b/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs index 52534d5a5..6fb79379a 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs @@ -77,8 +77,12 @@ namespace NzbDrone.Core.Messaging.Commands _trackCommands.Store(command); + // TODO: We should use async await (once we get 4.5) or normal Task Continuations on Command processing to prevent blocking the TaskScheduler. + // For now we use TaskCreationOptions 0x10, which is actually .net 4.5 HideScheduler. + // This will detach the scheduler from the thread, causing new Task creating in the command to be executed on the ThreadPool, avoiding a deadlock. + // Please note that the issue only shows itself on mono because since Microsoft .net implementation supports Task inlining on WaitAll. _taskFactory.StartNew(() => ExecuteCommand(command) - , TaskCreationOptions.PreferFairness) + , TaskCreationOptions.PreferFairness | (TaskCreationOptions)0x10) .LogExceptions(); return command;