public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) { DownloadItemViewModel _item = null; //初始暂停 if (string.IsNullOrWhiteSpace(downloadItem.FullPath)) { callback.Pause(); } else//初始化完毕 { //插入记录 if (!DownloadMap.ContainsKey(downloadItem.Id)) { _item = new DownloadItemViewModel(); _item.customDownloadHandler = this; _item.UpDate(downloadItem); DownloadMap.Add(downloadItem.Id, _item); //Console.WriteLine("----insert {0}", _item.ID); } else { //获取对应记录 _item = DownloadMap[downloadItem.Id]; } //继续开始下载 if (!_item.IsInitalized) { _item.IsInitalized = true; callback.Resume(); } } if (_item != null && _item.IsInitalized) { _item.UpDate(downloadItem); //callback管理 if (callback.IsDisposed) { Console.WriteLine("Callback disposed"); } else { if (ControlMap.ContainsKey(_item.ID)) { ControlMap[_item.ID] = callback; } else { ControlMap.Add(_item.ID, callback); } } //更新 OnUpdated?.BeginInvoke(this, _item, (o) => { if (_item.NeedPause) { try { GetControl(_item.ID)?.Pause(); } catch (Exception e) { Console.WriteLine("Cancel Error :{0}", e.Message); } _item.NeedPause = false; _item.IsPaused = true; } if (_item.NeedCancel) { try { GetControl(_item.ID)?.Cancel(); } catch (Exception e) { Console.WriteLine("Cancel Error :{0}", e.Message); } _item.NeedCancel = false; _item.IsCancelled = true; } if (_item.NeedResume) { try { GetControl(_item.ID)?.Resume(); } catch (Exception e) { Console.WriteLine("Resume Error :{0}", e.Message); } _item.NeedResume = false; _item.IsPaused = false; } OnUpdated.Invoke(this, _item); }, null); } }