/// <summary> /// 从淘宝获取最新数据 /// </summary> /// <param name="pageno"></param> /// <param name="pageSize"></param> /// <param name="totalResults"></param> /// <param name="tradeRefundList"></param> public void GetNewTradeRefund(string session, int pageno, int pageSize, out int totalResults , List <Alading.Entity.TradeRefund> tradeRefundList, List <string> refundIDList) { TradeReq tradeReq = new TradeReq(); tradeReq.PageNo = pageno; //页数 tradeReq.PageSize = pageSize; //每页的数量 string fields = "refund_id,order_status,modified"; //API参数 TradeRsp tradeRsp = TopService.RefundsReceiveGet(session, fields, tradeReq); /*未获取到数据*/ if (tradeRsp == null || tradeRsp.TotalResults == 0) { totalResults = 0; return; } totalResults = tradeRsp.TotalResults; foreach (Alading.Taobao.Entity.Refund refund in tradeRsp.Refunds.Refund) { Alading.Entity.TradeRefund newTradeRefund = new Alading.Entity.TradeRefund(); newTradeRefund.refund_id = refund.Rid; //退货单号 newTradeRefund.order_status = refund.OrderStatus == null ? string.Empty : refund.OrderStatus; //退款对应的订单交易状态 newTradeRefund.modified = DateTime.Parse(refund.Modified); //对象修改时间 tradeRefundList.Add(newTradeRefund); refundIDList.Add(refund.Rid); } }
/// <summary> /// 查询买家申请的退款列表 /// 所有参数可以为空 /// </summary> /// <returns></returns> public static TradeRsp RefundsApplyGet(string session, TradeReq tradereq) { try { TopDictionary paramsTable = new TopDictionary(); paramsTable.Add("method", "taobao.refunds.apply.get"); paramsTable.Add("fields", "refund_id,tid,title,buyer_nick,seller_nick,total_fee,status,created,refund_fee"); paramsTable.Add("status", tradereq.Status); paramsTable.Add("seller_nick", tradereq.SellerNick); paramsTable.Add("page_no", tradereq.PageNo); paramsTable.Add("page_size", tradereq.PageSize); paramsTable.Add("type", tradereq.Type); paramsTable.Add("session", session); return(TopUtils.DeserializeObject <TradeRsp>(TopUtils.InvokeAPI(paramsTable, APIInvokeType.Private))); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// 搜索当前会话用户作为卖家已卖出的增量交易数据 /// start_modified,end_modified 必须填,其余可以为空 /// </summary> public static TradeRsp TradesSoldIncrementGet(string session, TradeReq tradereq) { try { TopDictionary paramsTable = new TopDictionary(); paramsTable.Add("method", "taobao.trades.sold.increment.get"); paramsTable.Add("fields", "seller_nick,buyer_nick,title,type,created,sid,tid,seller_rate,buyer_rate,status,payment,discount_fee,adjust_fee,post_fee,total_fee,pay_time,end_time,modified,consign_time,buyer_obtain_point_fee,point_fee,real_point_fee,received_payment,commission_fee,alipay_no,pic_path,iid,num,price,cod_fee,cod_status,shipping_type,orders.title,orders.pic_path,orders.price,orders.num,orders.iid,orders.sku_id,orders.refund_status,orders.status,orders.oid,orders.total_fee,orders.payment,orders.discount_fee,orders.adjust_fee,orders.sku_properties_name,orders.item_meal_name,orders"); paramsTable.Add("start_modified", tradereq.StartCreated); paramsTable.Add("end_modified", tradereq.EndCreated); paramsTable.Add("status", tradereq.Status); paramsTable.Add("page_no", tradereq.PageNo); paramsTable.Add("page_size", tradereq.PageSize); paramsTable.Add("type", tradereq.Type); paramsTable.Add("session", session); return(TopUtils.DeserializeObject <TradeRsp>(TopUtils.InvokeAPI(paramsTable, APIInvokeType.Private))); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// 查询卖家收到的退款列表 /// 所有参数都可以为空 /// </summary> /// <returns></returns> public static TradeRsp RefundsReceiveGet(string session, string fields, TradeReq tradereq) { try { TopDictionary paramsTable = new TopDictionary(); paramsTable.Add("method", "taobao.refunds.receive.get"); paramsTable.Add("status", tradereq.Status); paramsTable.Add("buyer_nick", tradereq.BuyerNick); paramsTable.Add("page_no", tradereq.PageNo); paramsTable.Add("page_size", tradereq.PageSize); paramsTable.Add("fields", fields); paramsTable.Add("type", tradereq.Type); paramsTable.Add("start_modified", tradereq.StartModified); paramsTable.Add("end_modified", tradereq.EndModified); paramsTable.Add("session", session); return(TopUtils.DeserializeObject <TradeRsp>(TopUtils.InvokeAPI(paramsTable, APIInvokeType.Private))); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// 查询卖家收到的退款列表 /// 所有参数都可以为空 /// </summary> /// <returns></returns> public static TradeRsp RefundsReceiveGet(string session, TradeReq tradereq) { try { TopDictionary paramsTable = new TopDictionary(); paramsTable.Add("method", "taobao.refunds.receive.get"); paramsTable.Add("status", tradereq.Status); paramsTable.Add("buyer_nick", tradereq.BuyerNick); paramsTable.Add("page_no", tradereq.PageNo); paramsTable.Add("page_size", tradereq.PageSize); paramsTable.Add("fields", "refund_id,tid,title,buyer_nick,seller_nick,total_fee,status,created,refund_fee,oid,good_status,company_name,sid,payment,reason,desc,has_good_return,modified,order_status"); paramsTable.Add("type", tradereq.Type); paramsTable.Add("start_modified", tradereq.StartModified); paramsTable.Add("end_modified", tradereq.EndModified); paramsTable.Add("session", session); return(TopUtils.DeserializeObject <TradeRsp>(TopUtils.InvokeAPI(paramsTable, APIInvokeType.Private))); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// 搜索当前会话用户作为卖家已卖出的交易数据 /// 所有参数都可以为空 /// </summary> /// <param name="tradereq"></param> /// <returns></returns> public static TradeRsp TradesSoldGet(string session, TradeReq tradereq) { try { TopDictionary paramsTable = new TopDictionary(); paramsTable.Add("method", "taobao.trades.sold.get"); paramsTable.Add("fields", "seller_nick,buyer_nick,title,type,tid,status"); paramsTable.Add("start_created", tradereq.StartCreated); paramsTable.Add("end_created", tradereq.EndCreated); paramsTable.Add("page_no", tradereq.PageNo); paramsTable.Add("page_size", tradereq.PageSize); paramsTable.Add("title", tradereq.Title); paramsTable.Add("status", tradereq.Status); paramsTable.Add("buyer_nick", tradereq.BuyerNick); paramsTable.Add("rate_status", tradereq.RateStatus); paramsTable.Add("type", tradereq.Type); paramsTable.Add("session", session); return(TopUtils.DeserializeObject <TradeRsp>(TopUtils.InvokeAPI(paramsTable, APIInvokeType.Private))); } catch (System.Exception ex) { throw ex; } }
void mainWorker_DoWork(object sender, DoWorkEventArgs e) { try { BackgroundWorker worker = sender as BackgroundWorker; //threadCount = Convert.ToInt32(spinEditThreadCount.Value);//这里不必要了,在点击按钮时已经赋值 int pageSize = 40; for (int k = 0; k < downShopList.Count; k++) { var shop = downShopList[k]; if (worker.CancellationPending) { e.Cancel = true; return; } ReportState state = new ReportState() { Current = k + 1, Total = downShopList.Count, Message = string.Format("正在同步店铺 {0} 的客户...", shop.title), }; worker.ReportProgress(1, state); #region initialize query time DateTime begin = DateTime.Now; DateTime end = DateTime.Now; switch (typeIndex) { // 15 days case 0: begin = DateTime.Now.AddDays(-15); break; // customize case 1: begin = this.dateEditBegin.DateTime; end = this.dateEditEnd.DateTime; break; // since shop created case 2: begin = shop.created; break; } #endregion #region Get total trade count TradeReq request = new TradeReq(); request.Status = null; request.PageSize = pageSize; request.PageNo = 1; request.StartCreated = begin.ToString("yyyy-MM-dd HH:mm:ss"); request.EndCreated = end.ToString("yyyy-MM-dd HH:mm:ss"); string sessionkey = SystemHelper.GetSessionKey(shop.nick); TradeRsp response = TopService.TradesSoldGet(sessionkey, request); sub_done = 0; sub_total = response.TotalResults; #endregion if (sub_total == 0) { continue; } #region Dispatch task to thread threadList.Clear(); if (sub_total <= pageSize) { #region total count < page size SycTaskArgs task = new SycTaskArgs { ShopNick = shop.nick, PageSize = pageSize, QueryBeginTime = begin, QueryEndTime = end, }; task.PageNoList.Add(1); BackgroundWorker w = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true, }; w.RunWorkerCompleted += new RunWorkerCompletedEventHandler(w_RunWorkerCompleted); w.ProgressChanged += new ProgressChangedEventHandler(w_ProgressChanged); w.DoWork += new DoWorkEventHandler(w_DoWork); taskList.Add(task); threadList.Add(w); threadCount = 1; #endregion } else { int pageCount = (sub_total % pageSize == 0) ? (sub_total / pageSize) : (sub_total / pageSize + 1); if (threadCount < pageCount) { #region page count < thread count threadCount = pageCount; for (int i = 0; i < threadCount; i++) { SycTaskArgs task = new SycTaskArgs { ShopNick = shop.nick, PageSize = 40, QueryBeginTime = begin, QueryEndTime = end, }; task.PageNoList.Add(i + 1); BackgroundWorker w = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true, }; w.RunWorkerCompleted += new RunWorkerCompletedEventHandler(w_RunWorkerCompleted); w.ProgressChanged += new ProgressChangedEventHandler(w_ProgressChanged); w.DoWork += new DoWorkEventHandler(w_DoWork); taskList.Add(task); threadList.Add(w); } #endregion } else { #region page count > thread count for (int i = 0; i < threadCount; i++) { SycTaskArgs task = new SycTaskArgs { ShopNick = shop.nick, PageSize = 40, QueryBeginTime = begin, QueryEndTime = end, }; BackgroundWorker w = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true, }; w.RunWorkerCompleted += new RunWorkerCompletedEventHandler(w_RunWorkerCompleted); w.ProgressChanged += new ProgressChangedEventHandler(w_ProgressChanged); w.DoWork += new DoWorkEventHandler(w_DoWork); taskList.Add(task); threadList.Add(w); } int index = 0; for (int i = 0; i < pageCount; i++, index++) { if (index >= taskList.Count) { index = 0; } taskList[i].PageNoList.Add(i + 1); } #endregion } } #endregion #region run tasks signal = new AutoResetEvent(false); for (int i = 0; i < threadCount; i++) { threadList[i].RunWorkerAsync(taskList[i]); } signal.WaitOne(); #endregion } } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } }
void w_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; SycTaskArgs task = e.Argument as SycTaskArgs; foreach (var p in task.PageNoList) { #region get trade information //这里改成mainWorker,即主线程取消子线程工作全部停止 if (mainWorker.CancellationPending) { e.Cancel = true; return; } TradeReq request = new TradeReq(); TradeRsp response = null; request.Status = null; request.PageSize = task.PageSize; request.PageNo = p; request.StartCreated = task.QueryBeginTime.ToString("yyyy-MM-dd HH:mm:ss"); request.EndCreated = task.QueryEndTime.ToString("yyyy-MM-dd HH:mm:ss"); string sessionkey = SystemHelper.GetSessionKey(task.ShopNick); response = TopService.TradesSoldGet(sessionkey, request); #endregion #region if getting trade failed do next if (response == null || response.Trades == null) { lock (vlock) { sub_done += task.PageSize; } continue; } #endregion foreach (var t in response.Trades.Trade) { //if (worker.CancellationPending) //这里改成mainWorker,即主线程取消子线程工作全部停止 if (mainWorker.CancellationPending) { e.Cancel = true; return; } lock (vlock) { sub_done++; } TradeRsp fulltrade = TopService.TradeFullinfoGet(sessionkey, t.Tid); #region if getting trade detail failed do next if (fulltrade == null || fulltrade.Trade == null) { ReportState state = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("同步客户 {0} 失败:无法获取交易信息!", t.BuyerNick), }; worker.ReportProgress(0, state); continue; } #endregion UserRsp buyer = TopService.UserGet(sessionkey, fulltrade.Trade.BuyerNick, fulltrade.Trade.AlipayNo); #region if getting buyer detail failed do next if (buyer == null || buyer.User == null) { ReportState state = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("同步客户 {0} 失败:无法获取买家信息!", t.BuyerNick), }; worker.ReportProgress(0, state); continue; } #endregion Alading.Entity.Consumer consumer = Alading.Business.ConsumerService.GetConsumer(fulltrade.Trade.BuyerNick); if (consumer == null) { #region Consumer is not existed and save it consumer = new Alading.Entity.Consumer(); consumer.nick = buyer.User.Nick; consumer.sex = buyer.User.Sex; consumer.buyer_zip = buyer.User.Location.Zip; consumer.location_city = buyer.User.Location.City; consumer.location_state = buyer.User.Location.State; consumer.location_district = buyer.User.Location.District; consumer.location_address = buyer.User.Location.Address; consumer.location_country = buyer.User.Location.Address; consumer.birthday = buyer.User.Birthday; consumer.credit = buyer.User.BuyerCredit.ToString(); consumer.level = buyer.User.BuyerCredit.Level; consumer.score = buyer.User.BuyerCredit.Score; consumer.status = buyer.User.Status; consumer.created = DateTime.Parse(buyer.User.Created); consumer.last_visit = buyer.User.LastVisit; consumer.mobilephone = fulltrade.Trade.ReceiverMobile; consumer.phone = fulltrade.Trade.ReceiverPhone; consumer.email = fulltrade.Trade.BuyerEmail; consumer.buyer_name = fulltrade.Trade.ReceiverName; consumer.alipay = fulltrade.Trade.AlipayNo; ReturnType result = Alading.Business.ConsumerService.AddConsumer(consumer); if (result == ReturnType.Success) { ReportState state = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("同步客户 {0} 信息成功!", consumer.nick), }; worker.ReportProgress(1, state); Alading.Entity.ConsumerAddress addr = Alading.Business.ConsumerAddressService.GetConsumerAddress( c => c.tid == fulltrade.Trade.Tid).FirstOrDefault(); if (addr == null) { addr = new Alading.Entity.ConsumerAddress { buyer_nick = fulltrade.Trade.BuyerNick, location_address = fulltrade.Trade.ReceiverAddress, location_city = fulltrade.Trade.ReceiverCity, location_country = buyer.User.Location.Country, location_district = fulltrade.Trade.ReceiverDistrict, location_state = fulltrade.Trade.ReceiverState, location_zip = fulltrade.Trade.ReceiverZip, receiver_mobile = fulltrade.Trade.ReceiverMobile, receiver_name = fulltrade.Trade.ReceiverName, receiver_phone = fulltrade.Trade.ReceiverPhone, receiver_zip = fulltrade.Trade.ReceiverZip, tid = fulltrade.Trade.Tid, }; result = Alading.Business.ConsumerAddressService.AddConsumerAddress(addr); if (result == ReturnType.Success) { state = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("同步客户 {0} 地址信息成功!", consumer.nick), }; worker.ReportProgress(1, state); } else { state = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("同步客户 {0} 地址信息失败:数据保存失败!", consumer.nick), }; worker.ReportProgress(1, state); } } } else { ReportState state = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("同步客户 {0} 信息失败:数据保存失败!", consumer.nick), }; worker.ReportProgress(1, state); continue; } #endregion } else { #region Consumer existed and update address information ReportState state0 = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("客户 {0} 已存在!", consumer.nick), }; worker.ReportProgress(0, state0); Alading.Entity.ConsumerAddress addr = Alading.Business.ConsumerAddressService.GetConsumerAddress( c => c.tid == fulltrade.Trade.Tid).FirstOrDefault(); if (addr == null) { addr = new Alading.Entity.ConsumerAddress { buyer_nick = fulltrade.Trade.BuyerNick, location_address = fulltrade.Trade.ReceiverAddress, location_city = fulltrade.Trade.ReceiverCity, location_country = buyer.User.Location.Country, location_district = fulltrade.Trade.ReceiverDistrict, location_state = fulltrade.Trade.ReceiverState, location_zip = fulltrade.Trade.ReceiverZip, receiver_mobile = fulltrade.Trade.ReceiverMobile, receiver_name = fulltrade.Trade.ReceiverName, receiver_phone = fulltrade.Trade.ReceiverPhone, receiver_zip = fulltrade.Trade.ReceiverZip, tid = fulltrade.Trade.Tid, }; ReturnType result = Alading.Business.ConsumerAddressService.AddConsumerAddress(addr); if (result == ReturnType.Success) { ReportState state = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("同步客户 {0} 地址信息成功!", consumer.nick), }; worker.ReportProgress(1, state); } else { ReportState state = new ReportState { Total = sub_total, Current = sub_done, Message = string.Format("同步客户 {0} 地址信息失败:数据保存失败!", consumer.nick), }; worker.ReportProgress(1, state); } } #endregion } } } }
void mainWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; StringBuilder str_fail = new StringBuilder(); TradeReq tradeReq = new TradeReq(); //获取状态 tradeReq.Status = TradeStatus; //总交易量清空 TotalProessNum = 0; //错误列表清空 failedTrade = new FailedTrade(); tradeReq.PageSize = 100; //每页总数 tradeReq.PageNo = 1; //页数 /*计算总的交易量 即总进度条计算*/ for (int j = 0; j < shop_List.Count; j++) { try { #region 时间设置 /*选择近十五天*/ if (cmbSelectTime.SelectedIndex == 0) { tradeReq.StartCreated = this.dateEditBegin.DateTime.ToString("yyyy-MM-dd HH:mm:ss"); tradeReq.EndCreated = this.dateEditEnd.DateTime.ToString("yyyy-MM-dd HH:mm:ss"); } else/*开店至今*/ { tradeReq.StartCreated = shop_List[j].created.ToString("yyyy-MM-dd HH:mm:ss"); tradeReq.EndCreated = DateTime.Now.AddDays(-15).ToString("yyyy-MM-dd HH:mm:ss"); } #endregion //获取sessionkey string sessionkey = SystemHelper.GetSessionKey(shop_List[j].nick); //从淘宝上获取数据 TradeRsp tradeRsp = TopService.TradesSoldGet(sessionkey, tradeReq); //订单获取失败 if (tradeRsp != null || tradeRsp.Trades != null) { TotalProessNum += tradeRsp.TotalResults; } } catch (System.Exception ex) { BeginInvoke(new Action(() => { OrderDown.Items.Insert(0, string.Format("{0} {1}", DateTime.Now.ToString("HH:mm:ss"), ex.Message)); })); return; } } /*各个店铺的交易处理*/ for (int j = 0; j < shop_List.Count; j++) { //清空线程列表 workerList.Clear(); //清空总线程量 totalThreadCount = 0; //当前交易量 currentProessNum = 0; /*信息*/ UserState DoState = new UserState(); DoState.shopNick = shop_List[j].nick; DoState.message = "开始处理!"; mainWorker.ReportProgress(0, DoState); try { //交易列表 List <string> tidList = new List <string>(); #region 时间设置 /*选择近十五天*/ if (cmbSelectTime.SelectedIndex == 0) { tradeReq.StartCreated = this.dateEditBegin.DateTime.ToString("yyyy-MM-dd HH:mm:ss"); tradeReq.EndCreated = this.dateEditEnd.DateTime.ToString("yyyy-MM-dd HH:mm:ss"); } else/*开店至今*/ { tradeReq.StartCreated = shop_List[j].created.ToString("yyyy-MM-dd HH:mm:ss"); tradeReq.EndCreated = DateTime.Now.AddDays(-15).ToString("yyyy-MM-dd HH:mm:ss"); } #endregion //获取sessionkey string sessionkey = SystemHelper.GetSessionKey(shop_List[j].nick); //从淘宝上获取数据 TradeRsp tradeRsp = TopService.TradesSoldGet(sessionkey, tradeReq); //订单获取失败 if (tradeRsp == null || tradeRsp.Trades == null) { //异步操作 BeginInvoke(new Action(() => { OrderDown.Items.Insert(0, string.Format("{0} 网络异常,{1}店铺的订单下载失败!", DateTime.Now.ToString("HH:mm:ss"), shop_List[j].nick)); })); str_fail.Append(shop_List[j].nick); str_fail.Append(" "); continue; } if (tradeRsp != null) { foreach (Alading.Taobao.Entity.Trade tradeObj in tradeRsp.Trades.Trade) { tidList.Add(tradeObj.Tid); } /*foreach*/ } /*if*/ //店铺的总交易量 int totalResults = tradeRsp.TotalResults; BeginInvoke(new Action(() => { OrderDown.Items.Insert(0, string.Format("{0} 店铺{1}共{2}订单!", DateTime.Now.ToString("HH:mm:ss"), shop_List[j].nick, totalResults)); })); #region 计算是否需要分页获取 int PageTotalNum = 0; /*总页数*/ int PageCurrentNo = 0; /*当前页数*/ //计算总页数 PageTotalNum = (tradeRsp.TotalResults % tradeReq.PageSize == 0) ? (tradeRsp.TotalResults / tradeReq.PageSize) : (tradeRsp.TotalResults / tradeReq.PageSize + 1); /*有多余两页的订单*/ if (PageTotalNum >= 2) { for (PageCurrentNo = 2; PageCurrentNo < PageTotalNum + 1; PageCurrentNo++) { tradeReq.PageNo = PageCurrentNo; tradeRsp = TopService.TradesSoldGet(sessionkey, tradeReq); if (tradeRsp != null && tradeRsp.Trades != null) { foreach (Taobao.Entity.Trade tradeObj in tradeRsp.Trades.Trade) { if (!tidList.Contains(tradeObj.Tid)) { tidList.Add(tradeObj.Tid); } } } //if else /*获取失败*/ { if (!str_fail.ToString().Contains(shop_List[j].nick)) { str_fail.Append(shop_List[j].nick); str_fail.Append(" "); BeginInvoke(new Action(() => { OrderDown.Items.Insert(0, string.Format("{0} 网络异常,{1}店铺的订单下载失败!", DateTime.Now.ToString("HH:mm:ss"), shop_List[j].nick)); })); } break; } } //for } //if #endregion /*总交易数小于线程数*/ if (totalResults < threadCount) { threadCount = totalResults; } //每个线程交易下载量 int tradePageSize = (totalResults % threadCount == 0) ? (totalResults / threadCount) : (totalResults / threadCount + 1); #region 开启多线程 for (int i = 0; i < threadCount; i++) { //获取分给每个线程的tid列表 List <string> TradeTidList = tidList.Skip(i * tradePageSize).Take(tradePageSize).ToList(); /*线程配置*/ BackgroundWorker TradeWorker = new BackgroundWorker(); TradeWorker.WorkerReportsProgress = true; TradeWorker.WorkerSupportsCancellation = true; TradeWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); TradeWorker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); TradeWorker.DoWork += new DoWorkEventHandler(worker_DoWork); //添加到线程列表 workerList.Add(TradeWorker); /*参数传递*/ TradeTask tradeTask = new TradeTask(); tradeTask.shopNic = shop_List[j].nick; tradeTask.ShopTradeList = TradeTidList; tradeTask.threadIndex = i + 1; tradeTask.sessionKey = sessionkey; tradeTask.totalNum = totalResults; TradeWorker.RunWorkerAsync(tradeTask); } #endregion } catch (System.Exception ex) { BeginInvoke(new Action(() => { if (ex.Message.Contains("Remote service error")) { OrderDown.Items.Insert(0, string.Format("{0} {1}", DateTime.Now.ToString("HH:mm:ss"), "不能连接远程服务器,请多尝试几次下载!".ToString())); } })); /*进度记录*/ ProcessRecord = 0; TotalProessNum = 0; TotalProessNum = 0; BeginInvoke(new Action(() => { btnDownOrders.Enabled = true; })); return; } //信号量,阻塞当前线程,这里阻塞的是下载主线程 autoReset.WaitOne(); }/*foreach 对店铺遍历*/ }