private void OnDone(object sender, AsyncOperationCompletedEventArgs e) { UserState ut = e.UserState as UserState; if (this.states.Contains(ut) == false) return; this.states.Remove(ut); if (e.Error == null && e.Cancelled == false) { if (ut.opType == UserState.OperationType.query || ut.opType == UserState.OperationType.queryForBackup) { if (e.Feed != null) { this.photoFeed = e.Feed as PicasaFeed; this.InitializeList(ut.filename); } } if (ut.opType == UserState.OperationType.upload) { if (e.Entry != null) { ListViewItem item = new ListViewItem(e.Entry.Title.Text); item.Tag = e.Entry; this.PhotoList.Items.Add(item); this.FileInfo.Text = "Upload succeeded"; } } if (ut.opType == UserState.OperationType.download || ut.opType == UserState.OperationType.downloadList) { if (e.ResponseStream != null) { WriteFile(ut.filename, e.ResponseStream); this.FileInfo.Text = "Saved file: " + ut.filename; } } if (ut.opType == UserState.OperationType.downloadList) { // we need to create a new object for uniqueness UserState u = new UserState(); u.counter = ut.counter + 1; u.feed = ut.feed; u.foldername = ut.foldername; u.opType = UserState.OperationType.downloadList; if (u.feed.Entries.Count > 0) { u.feed.Entries.RemoveAt(0); this.PhotoList.Items.RemoveAt(0); } this.states.Add(u); SaveAnotherPictureDelegate d = new SaveAnotherPictureDelegate(this.CreateAnotherSaveFile); this.BeginInvoke(d, u); } if (ut.opType == UserState.OperationType.queryForBackup) { UserState u = new UserState(); u.opType = UserState.OperationType.downloadList; u.feed = this.photoFeed; u.counter = 1; u.foldername = ut.foldername; u.filename = ut.foldername + "\\image1.jpg"; this.states.Add(u); SaveAnotherPictureDelegate d = new SaveAnotherPictureDelegate(this.CreateAnotherSaveFile); this.BeginInvoke(d, u); } } this.progressBar.Value = 0; if (this.states.Count == 0) { this.CancelAsync.Enabled = false; this.CancelAsync.Visible = false; } }