From 052a3bf47ee722d67cf48392bacc29865e36bc72 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sun, 8 Jun 2014 09:50:29 +0200 Subject: [PATCH] Fixed mono fix by checking if the Enum value exists in the runtime. --- .../Messaging/Commands/CommandExecutor.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs b/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs index 4ad89fe5e..2f3c72ee0 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs @@ -81,11 +81,18 @@ namespace NzbDrone.Core.Messaging.Commands // 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) -// This breaks on systems that don't have .Net 4.5 installed (but works fine when it does, even though we are targetting 4.0) -// , TaskCreationOptions.PreferFairness | (TaskCreationOptions)0x10) - .LogExceptions(); + if (Enum.IsDefined(typeof(TaskCreationOptions), (TaskCreationOptions)0x10)) + { + _taskFactory.StartNew(() => ExecuteCommand(command) + , TaskCreationOptions.PreferFairness | (TaskCreationOptions)0x10) + .LogExceptions(); + } + else + { + _taskFactory.StartNew(() => ExecuteCommand(command) + , TaskCreationOptions.PreferFairness) + .LogExceptions(); + } return command; }