1199 {
1200 _progress.HasUploadPhase = true;
1202 try
1203 {
1204 if (request.RequestUri.Scheme == Uri.UriSchemeFile)
1205 {
1207 footer = (
array =
null);
1209 }
1210 using (
Stream writeStream = await request.GetRequestStreamAsync().ConfigureAwait(continueOnCapturedContext: false))
1211 {
1212 if (header != null)
1213 {
1215 _progress.BytesSent += header.Length;
1217 }
1218 if (readStream != null)
1219 {
1220 using (readStream)
1221 {
1222 while (true)
1223 {
1224 int bytesRead2 = await readStream.
ReadAsync(
new Memory<byte>(
buffer)).ConfigureAwait(continueOnCapturedContext: false);
1225 if (bytesRead2 <= 0)
1226 {
1227 break;
1228 }
1230 _progress.BytesSent += bytesRead2;
1232 }
1233 }
1234 }
1235 else
1236 {
1237 int bytesRead2 = 0;
1238 while (bytesRead2 <
buffer.Length)
1239 {
1240 int toWrite = buffer.Length - bytesRead2;
1241 if (chunkSize != 0 && toWrite > chunkSize)
1242 {
1243 toWrite = chunkSize;
1244 }
1246 bytesRead2 += toWrite;
1247 _progress.BytesSent += toWrite;
1249 }
1250 }
1251 if (footer != null)
1252 {
1254 _progress.BytesSent += footer.Length;
1256 }
1257 }
1259 }
1260 catch (Exception ex) when (!(ex is OutOfMemoryException))
1261 {
1264 }
1265 finally
1266 {
1268 {
1269 completionDelegate(
null,
exception, asyncOp);
1270 }
1271 }
1272 }
Task WriteAsync(byte[] buffer, int offset, int count)
Task< int > ReadAsync(byte[] buffer, int offset, int count)
async void DownloadBitsAsync(WebRequest request, Stream writeStream, AsyncOperation asyncOp, Action< byte[], Exception, AsyncOperation > completionDelegate)
static Exception GetExceptionToPropagate(Exception e)
static void AbortRequest(WebRequest request)
void PostProgressChanged(AsyncOperation asyncOp, ProgressData progress)
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)