public override void ExecuteAsync() { lock (SyncRoot) { SetStatus(TaskStatus.Running); if (mre != null) { mre.Reset(); } } try { wc = new AsyncWebClient(); wc.Timeout = (30 * 1000); // 30 Seconds if (feed.LastDownloadError == FeedDownloadError.None && feed.LastDownloadTime != DateTime.MinValue) { wc.IfModifiedSince = feed.LastDownloadTime.ToUniversalTime(); } wc.DownloadStringCompleted += OnDownloadDataReceived; feed.DownloadStatus = FeedDownloadStatus.Downloading; wc.DownloadStringAsync(new Uri(feed.Url)); } catch (Exception e) { if (wc != null) { wc.DownloadStringCompleted -= OnDownloadDataReceived; } EmitCompletionEvents(FeedDownloadError.DownloadFailed); Log.Error(e); } }
private async void GetArtists(object sender, RoutedEventArgs e) { if (cancellationToken != null) { cancellationToken.Cancel(); getArtists.IsEnabled = false; return; } getArtists.Content = "Cancel"; Artists.Clear(); try { cancellationToken = new CancellationTokenSource(); var wc = new AsyncWebClient(); await GetArtistsAsync(wc, cancellationToken.Token, new Progress<Artist>(a=>Artists.Add(a)), GetBitmapImage); } catch (TaskCanceledException) { MessageBox.Show("Cancelled"); } finally { getArtists.Content = "Get Artists"; cancellationToken = null; getArtists.IsEnabled = true; } }
private void DestroyWebClient() { if (wc != null) { wc.DownloadFileCompleted -= OnDownloadFileCompletedHandler; wc.DownloadProgressChanged -= OnDownloadProgressChangedHandler; wc.ResponseReceived -= OnResponseReceivedHandler; wc = null; } }
private void InitWebClient() { wc = new AsyncWebClient(); if (localStream.Length > 0) { wc.Range = Convert.ToInt32(localStream.Length); //Console.WriteLine ("Adding Range: {0}", wc.Range); } wc.Timeout = (5 * 60 * 1000); wc.DownloadFileCompleted += OnDownloadFileCompletedHandler; wc.DownloadProgressChanged += OnDownloadProgressChangedHandler; wc.ResponseReceived += OnResponseReceivedHandler; }