public async Task RunAsync(CancellationToken token = default(CancellationToken)) { var request = CreateRequest(); if (OnWriteAsync != null) { await OnWriteAsync.Invoke(request, token); } else { OnWrite?.Invoke(request); } using (token.Register(() => request.Abort(), false)) using (var response = (HttpWebResponse)await request.GetResponseAsync()) { token.ThrowIfCancellationRequested(); if (OnReadAsync != null) { await OnReadAsync.Invoke(response, token); } else { OnRead?.Invoke(response); } } }
public void Run() { var request = CreateRequest(); if (OnWrite != null) { OnWrite.Invoke(request); } else { OnWriteAsync?.Invoke(request, CancellationToken.None).GetAwaiter().GetResult(); } using (var response = (HttpWebResponse)request.GetResponse()) { if (OnRead != null) { OnRead?.Invoke(response); } else { OnReadAsync?.Invoke(response, CancellationToken.None).GetAwaiter().GetResult(); } } }
public async Task RunAsync() { var request = CreateRequest(); if (OnWriteAsync != null) { await OnWriteAsync.Invoke(request); } else if (OnWrite != null) { OnWrite.Invoke(request); } using (var response = (HttpWebResponse)await request.GetResponseAsync()) { if (OnReadAsync != null) { await OnReadAsync.Invoke(response); } else if (OnRead != null) { OnRead?.Invoke(response); } } }