diff --git a/src/Machine.Specifications.Core/Runner/Impl/DelegateRunner.cs b/src/Machine.Specifications.Core/Runner/Impl/DelegateRunner.cs index cb0e4cec..d55121e3 100644 --- a/src/Machine.Specifications.Core/Runner/Impl/DelegateRunner.cs +++ b/src/Machine.Specifications.Core/Runner/Impl/DelegateRunner.cs @@ -1,4 +1,6 @@ using System; +using System.Reflection; +using System.Runtime.CompilerServices; using System.Threading; namespace Machine.Specifications.Runner.Impl @@ -17,6 +19,13 @@ public DelegateRunner(Delegate target, params object[] args) public void Execute() { + if (!IsAsyncVoid()) + { + target.DynamicInvoke(args); + + return; + } + var currentContext = SynchronizationContext.Current; var context = new AsyncSynchronizationContext(currentContext); @@ -39,5 +48,11 @@ public void Execute() SynchronizationContext.SetSynchronizationContext(currentContext); } } + + private bool IsAsyncVoid() + { + return target.Method.ReturnType == typeof(void) && + target.Method.GetCustomAttribute() != null; + } } }