diff --git a/castle.core.asyncinterceptor.sln b/castle.core.asyncinterceptor.sln
index e0fe9d5..1559145 100644
--- a/castle.core.asyncinterceptor.sln
+++ b/castle.core.asyncinterceptor.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.26403.3
+VisualStudioVersion = 15.0.27004.2006
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F820D2E2-6C9C-4165-9C13-C77B2737A5AC}"
EndProject
@@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{CE54F76E-8
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Castle.Core.AsyncInterceptor.Tests", "test\Castle.Core.AsyncInterceptor.Tests\Castle.Core.AsyncInterceptor.Tests.csproj", "{25AAC675-D2A0-4D20-97C8-FF1E28307E6E}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Castle.Core", "..\Core\src\Castle.Core\Castle.Core.csproj", "{DA7FD5D8-6394-4650-9095-A3EEF700B9C8}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -25,6 +27,10 @@ Global
{25AAC675-D2A0-4D20-97C8-FF1E28307E6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25AAC675-D2A0-4D20-97C8-FF1E28307E6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25AAC675-D2A0-4D20-97C8-FF1E28307E6E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DA7FD5D8-6394-4650-9095-A3EEF700B9C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DA7FD5D8-6394-4650-9095-A3EEF700B9C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DA7FD5D8-6394-4650-9095-A3EEF700B9C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DA7FD5D8-6394-4650-9095-A3EEF700B9C8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -32,5 +38,9 @@ Global
GlobalSection(NestedProjects) = preSolution
{51BA6816-5FDB-4AE7-A473-4C5CF1C1FAF4} = {F820D2E2-6C9C-4165-9C13-C77B2737A5AC}
{25AAC675-D2A0-4D20-97C8-FF1E28307E6E} = {CE54F76E-8913-4BBA-ADF3-A50777F55419}
+ {DA7FD5D8-6394-4650-9095-A3EEF700B9C8} = {F820D2E2-6C9C-4165-9C13-C77B2737A5AC}
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {7A10CB6D-F097-4F45-8CCA-FCBA06750817}
EndGlobalSection
EndGlobal
diff --git a/src/Castle.Core.AsyncInterceptor/AsyncDeterminationInterceptor.cs b/src/Castle.Core.AsyncInterceptor/AsyncDeterminationInterceptor.cs
index 9553f8a..5bb6b56 100644
--- a/src/Castle.Core.AsyncInterceptor/AsyncDeterminationInterceptor.cs
+++ b/src/Castle.Core.AsyncInterceptor/AsyncDeterminationInterceptor.cs
@@ -46,7 +46,6 @@ private enum MethodType
/// Intercepts a method .
///
/// The method invocation.
- [DebuggerStepThrough]
public virtual void Intercept(IInvocation invocation)
{
MethodType methodType = GetMethodType(invocation.Method.ReturnType);
diff --git a/src/Castle.Core.AsyncInterceptor/AsyncInterceptorBase.cs b/src/Castle.Core.AsyncInterceptor/AsyncInterceptorBase.cs
index 7012091..2dece3c 100644
--- a/src/Castle.Core.AsyncInterceptor/AsyncInterceptorBase.cs
+++ b/src/Castle.Core.AsyncInterceptor/AsyncInterceptorBase.cs
@@ -50,7 +50,7 @@ void IAsyncInterceptor.InterceptSynchronous(IInvocation invocation)
/// The method invocation.
void IAsyncInterceptor.InterceptAsynchronous(IInvocation invocation)
{
- invocation.ReturnValue = InterceptAsync(invocation, ProceedAsynchronous);
+ invocation.ReturnValue = InterceptAsyncWrapper(invocation, ProceedAsynchronous);
}
///
@@ -60,7 +60,7 @@ void IAsyncInterceptor.InterceptAsynchronous(IInvocation invocation)
/// The method invocation.
void IAsyncInterceptor.InterceptAsynchronous(IInvocation invocation)
{
- invocation.ReturnValue = InterceptAsync(invocation, ProceedAsynchronous);
+ invocation.ReturnValue = InterceptAsyncWrapper(invocation, ProceedAsynchronous);
}
///
@@ -90,12 +90,22 @@ private static GenericSynchronousHandler CreateHandler(Type returnType)
private static void InterceptSynchronousVoid(AsyncInterceptorBase me, IInvocation invocation)
{
- Task task = me.InterceptAsync(invocation, ProceedSynchronous);
+ Task task = me.InterceptAsyncWrapper(invocation, ProceedSynchronous);
// If the intercept task has yet to complete, wait for it.
if (!task.IsCompleted)
{
- Task.Run(() => task).Wait();
+ try
+ {
+ bool completed = Task.Run(async () => await task.ConfigureAwait(false)).Wait(2000);
+ if (!completed)
+ {
+ throw new Exception("I got sick of waiting 1.");
+ }
+ }
+ catch (AggregateException)
+ {
+ }
}
if (task.IsFaulted)
@@ -106,12 +116,22 @@ private static void InterceptSynchronousVoid(AsyncInterceptorBase me, IInvocatio
private static void InterceptSynchronousResult(AsyncInterceptorBase me, IInvocation invocation)
{
- Task task = me.InterceptAsync(invocation, ProceedSynchronous);
+ Task task = me.InterceptAsyncWrapper(invocation, ProceedSynchronous);
// If the intercept task has yet to complete, wait for it.
if (!task.IsCompleted)
{
- Task.Run(() => task).Wait();
+ try
+ {
+ bool completed = Task.Run(async () => await task.ConfigureAwait(false)).Wait(2000);
+ if (!completed)
+ {
+ throw new Exception("I got sick of waiting 2.");
+ }
+ }
+ catch (AggregateException)
+ {
+ }
}
if (task.IsFaulted)
@@ -182,5 +202,61 @@ private static async Task ProceedAsynchronous(IInvocation invo
TResult result = await originalReturnValue.ConfigureAwait(false);
return result;
}
+
+ private Task InterceptAsyncWrapper(IInvocation invocation, Func proceed)
+ {
+ // Do not return from this method until proceed is called or the implementor is finished
+ TaskCompletionSource