System.Net.WebClient.OpenReadTaskAsync C# (CSharp) Method

OpenReadTaskAsync() public method

public OpenReadTaskAsync ( System address ) : System.Threading.Tasks.Task
address System
return System.Threading.Tasks.Task
        public System.Threading.Tasks.Task<System.IO.Stream> OpenReadTaskAsync(System.Uri address) { throw null; }
        public System.IO.Stream OpenWrite(string address) { throw null; }

Same methods

WebClient::OpenReadTaskAsync ( string address ) : System.Threading.Tasks.Task

Usage Example

		async Task<int> GetBytes(string url, CancellationToken cancelToken, IProgress<DownloadBytesProgress> progressIndicator)
		{
			int receivedBytes = 0;
			int totalBytes = -1;
			WebClient client = new WebClient();

			using (var stream = await client.OpenReadTaskAsync(url))
			{
				byte[] buffer = new byte[4096];
				Int32.TryParse(client.ResponseHeaders[HttpResponseHeader.ContentLength], out totalBytes);

				for (;;)
				{
					int len = await stream.ReadAsync(buffer, 0, buffer.Length);
					if (len == 0)
					{
						await Task.Yield();
						break;
					}

					receivedBytes += len;
					cancelToken.ThrowIfCancellationRequested();

					if (progressIndicator != null)
					{
						DownloadBytesProgress args = new DownloadBytesProgress(url, receivedBytes, totalBytes);
						progressIndicator.Report(args);
					}
				}
			}
			return receivedBytes;
		}
All Usage Examples Of System.Net.WebClient::OpenReadTaskAsync