#602 Invoke APM callbacks on the threadpool.
This commit is contained in:
parent
6725d68559
commit
3a97a6bdfd
|
|
@ -139,19 +139,28 @@ namespace Microsoft.AspNetCore.Http.Internal
|
|||
|
||||
if (callback != null)
|
||||
{
|
||||
try
|
||||
// Offload callbacks to avoid stack dives on sync completions.
|
||||
var ignored = Task.Run(() =>
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Suppress exceptions on background threads.
|
||||
}
|
||||
try
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,7 +229,18 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
tcs.TrySetResult(toCopy);
|
||||
if (callback != null)
|
||||
{
|
||||
callback(tcs.Task);
|
||||
// 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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -232,19 +232,28 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
|
||||
if (callback != null)
|
||||
{
|
||||
try
|
||||
// Offload callbacks to avoid stack dives on sync completions.
|
||||
var ignored = Task.Run(() =>
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Suppress exceptions on background threads.
|
||||
}
|
||||
try
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,19 +184,28 @@ namespace Microsoft.AspNetCore.WebUtilities
|
|||
|
||||
if (callback != null)
|
||||
{
|
||||
try
|
||||
// Offload callbacks to avoid stack dives on sync completions.
|
||||
var ignored = Task.Run(() =>
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Suppress exceptions on background threads.
|
||||
}
|
||||
try
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 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