本文整理汇总了C#中RequestState.ServerCleanup方法的典型用法代码示例。如果您正苦于以下问题:C# RequestState.ServerCleanup方法的具体用法?C# RequestState.ServerCleanup怎么用?C# RequestState.ServerCleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestState
的用法示例。
在下文中一共展示了RequestState.ServerCleanup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectAsync
public async Task<WebSocket> ConnectAsync(Uri uri, CancellationToken cancellationToken)
{
var state = new RequestState(uri, _pathBase, cancellationToken, _application);
if (ConfigureRequest != null)
{
ConfigureRequest(state.Context.HttpContext.Request);
}
// Async offload, don't let the test code block the caller.
var offload = Task.Factory.StartNew(async () =>
{
try
{
await _application.ProcessRequestAsync(state.Context);
state.PipelineComplete();
state.ServerCleanup(exception: null);
}
catch (Exception ex)
{
state.PipelineFailed(ex);
state.ServerCleanup(ex);
}
finally
{
state.Dispose();
}
});
return await state.WebSocketTask;
}
示例2: SendAsync
/// <summary>
/// This adapts HttpRequestMessages to ASP.NET requests, dispatches them through the pipeline, and returns the
/// associated HttpResponseMessage.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var state = new RequestState(request, _pathBase, _application);
var requestContent = request.Content ?? new StreamContent(Stream.Null);
var body = await requestContent.ReadAsStreamAsync();
if (body.CanSeek)
{
// This body may have been consumed before, rewind it.
body.Seek(0, SeekOrigin.Begin);
}
state.Context.HttpContext.Request.Body = body;
var registration = cancellationToken.Register(state.AbortRequest);
// Async offload, don't let the test code block the caller.
var offload = Task.Factory.StartNew(async () =>
{
try
{
await _application.ProcessRequestAsync(state.Context);
state.CompleteResponse();
state.ServerCleanup(exception: null);
}
catch (Exception ex)
{
state.Abort(ex);
state.ServerCleanup(ex);
}
finally
{
registration.Dispose();
}
});
return await state.ResponseTask.ConfigureAwait(false);
}