本文整理汇总了C#中RequestState.Close方法的典型用法代码示例。如果您正苦于以下问题:C# RequestState.Close方法的具体用法?C# RequestState.Close怎么用?C# RequestState.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestState
的用法示例。
在下文中一共展示了RequestState.Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartAsyncRequest
private static void StartAsyncRequest(string url, RequestState requestState)
{
try {
requestState.StreamDst = File.OpenWrite(requestState.File);
if (!requestState.StreamDst.CanWrite) {
requestState.Close();
return;
}
HttpWebRequest request = CreateRequest(url);
requestState.request = request;
var result = request.BeginGetResponse(AsyncRespCallback, requestState);
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, TimeoutCallback, request, DefaultTimeout, true);
//allDone.WaitOne();
} catch (WebException e) {
requestState.Close();
HMS.LogError($"Ошибка асинхронного запроса на GitHub: {url}");
HMS.LogError($"{e.Message} Status: {e.Status}");
var respStream = e.Response?.GetResponseStream();
if (respStream != null) {
string resp = new StreamReader(respStream).ReadToEnd();
HMS.LogError(resp);
}
} catch (Exception e) {
requestState.Close();
HMS.LogError(e.ToString());
}
}
示例2: StartAsyncRequest
private static void StartAsyncRequest(string url, RequestState requestState)
{
IAsyncResult result = null;
try {
requestState.StreamDst = File.OpenWrite(requestState.File);
if (!requestState.StreamDst.CanWrite) {
requestState.Close();
return;
}
HttpWebRequest request = CreateRequest(url);
requestState.request = request;
result = request.BeginGetResponse(new AsyncCallback(AsyncRespCallback), requestState);
if (result != null)
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), request, DefaultTimeout, true);
//allDone.WaitOne();
} catch (WebException e) {
requestState.Close();
HMS.LogError("Ошибка асинхронного запроса на GitHub: " + url);
HMS.LogError(e.Message + " Status: " + e.Status.ToString());
if (e.Response != null) {
string resp = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
HMS.LogError(resp);
}
} catch (Exception e) {
requestState.Close();
HMS.LogError(e.ToString());
}
}