public BasicDownload(ESport sport, string url, Encoding encoding, string fileType = null) { this.downloadTimer = new Timer(); this.downloadTimer.Interval = timeoutValue; this.downloadTimer.Tick += TimerEventProcessor; this.Logs = new LogFile(sport, fileType); // 建立 this.Sport = sport; this.Uri = new Uri(url); if (this.Uri.ToString().IndexOf("bet007.com") != -1)//奧訊來源 { this.UrlList = UrlSetting.GetBet007Url(); this.ProxyList = ProxySetting.GetBet007Proxy(); // 取得奧訊代理 } if (this.Uri.ToString().IndexOf("d.asiascore.com") != -1)//asiascore來源 this.ProxyList = ProxySetting.GetAsiascoreProxy(); // 取得asiascore代理 if (this.Uri.ToString().IndexOf("www8.spbo1.com") != -1 || this.Uri.ToString().IndexOf("www8.spbo.com") != -1)//足球走勢來源 this.ProxyList = ProxySetting.GetSpbo1Proxy(); // 取得足球走勢代理 if (this.ProxyList == null || this.ProxyList.Count <=0) this.ProxyList = ProxySetting.GetProxy(sport); // 取得代理 this.Client = new WebClientEx(); //this.Client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); this.Client.Encoding = encoding; this.Client.DownloadDataCompleted += this.Client_DownloadDataCompleted; this.Client.DownloadStringCompleted += this.Client_DownloadStringCompleted; // 建立記錄檔操作 this.FileWrite = true; //奧訊代理 使用順位 ProxyUsing = 0;//預設值0 }
/// <summary> /// 釋放記憶體。 /// </summary> public void Dispose() { //解除委派處理 this.Client.DownloadDataCompleted -= this.Client_DownloadDataCompleted; this.Client.DownloadStringCompleted -= this.Client_DownloadStringCompleted; // 讀取資料就取消 this.Cancel(); // 釋放記憶體 this.Client.Dispose(); this.Client = null; this.Uri = null; this.Data = null; }