#602 Invoke APM callbacks on the threadpool.
This commit is contained in:
parent
6725d68559
commit
3a97a6bdfd
|
|
@ -138,6 +138,9 @@ namespace Microsoft.AspNetCore.Http.Internal
|
|||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
// Offload callbacks to avoid stack dives on sync completions.
|
||||
var ignored = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -147,11 +150,17 @@ namespace Microsoft.AspNetCore.Http.Internal
|
|||
{
|
||||
// Suppress exceptions on background threads.
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public override int EndRead(IAsyncResult asyncResult)
|
||||
{
|
||||
if (asyncResult == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(asyncResult));
|
||||
}
|
||||
|
||||
var task = (Task<int>)asyncResult;
|
||||
return task.GetAwaiter().GetResult();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,9 +228,20 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
TaskCompletionSource<int> tcs = new TaskCompletionSource<int>(state);
|
||||
tcs.TrySetResult(toCopy);
|
||||
if (callback != null)
|
||||
{
|
||||
// Offload callbacks to avoid stack dives on sync completions.
|
||||
var ignored = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Suppress exceptions on background threads.
|
||||
}
|
||||
});
|
||||
}
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
|
|
@ -239,6 +250,11 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
|
||||
public override int EndRead(IAsyncResult asyncResult)
|
||||
{
|
||||
if (asyncResult == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(asyncResult));
|
||||
}
|
||||
|
||||
Task<int> task = asyncResult as Task<int>;
|
||||
if (task != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -231,6 +231,9 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
// Offload callbacks to avoid stack dives on sync completions.
|
||||
var ignored = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -240,11 +243,17 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
{
|
||||
// Suppress exceptions on background threads.
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public override int EndRead(IAsyncResult asyncResult)
|
||||
{
|
||||
if (asyncResult == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(asyncResult));
|
||||
}
|
||||
|
||||
var task = (Task<int>)asyncResult;
|
||||
return task.GetAwaiter().GetResult();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,6 +183,9 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
// Offload callbacks to avoid stack dives on sync completions.
|
||||
var ignored = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -192,11 +195,17 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
{
|
||||
// Suppress exceptions on background threads.
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public override int EndRead(IAsyncResult asyncResult)
|
||||
{
|
||||
if (asyncResult == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(asyncResult));
|
||||
}
|
||||
|
||||
var task = (Task<int>)asyncResult;
|
||||
return task.GetAwaiter().GetResult();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue