Пример #1
0
        private void backWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker  = (BackgroundWorker)sender;
            List <string>    cidlist = (List <string>)e.Argument;

            for (int i = 0; i < cidlist.Count; i++)
            {
                if (isCancel)
                {
                    e.Cancel = true;
                    break;
                }
                string cid = cidlist[i];
                try
                {
                    UIHelper.DownPropsAndValues(cid, worker);
                }
                catch (Exception ex)
                {
                    if (ciderrorlist == null)
                    {
                        ciderrorlist = new List <string>();
                    }
                    ciderrorlist.Add(cid);
                    worker.ReportProgress(i + 1, string.Format("类目cid={0}异常信息:{1}", cid, ex.Message));
                    continue;
                }

                //更新ItemCat中此cid下的属性已完全下载
                ItemCatService.UpdateItemCatPropTag(cid, true);

                worker.ReportProgress(i + 1, cid);
            }
        }
Пример #2
0
        void batchworker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker        = (BackgroundWorker)sender;
            MyCidTask        cidtask       = (MyCidTask)e.Argument;
            List <string>    threadcidlist = cidtask.cidlist;

            #region 多类目下载一次存储方式,不采用
            ////分times次下载
            //int times = 100;
            //int size = 0;
            //if (threadcidlist.Count >= times)
            //{
            //    size = threadcidlist.Count % times == 0 ? threadcidlist.Count / times : threadcidlist.Count / times + 1;
            //}
            //else
            //{
            //    size = 1;
            //    times = threadcidlist.Count;
            //}
            #endregion

            int times = threadcidlist.Count;
            //int temp = 0;//作用是避免进度值propgress没有改变时得重复报告
            for (int i = 0; i < times; i++)
            {
                cidCompleteNum++;
                if (isCancel)
                {
                    e.Cancel = true;
                    break;
                }

                #region 多类目下载一次存储方式,不采用
                //List<string> cidlist = threadcidlist.Skip(i * size).Take(size).ToList();

                //List<string> valueWhereInCids = ItemPropValueService.GetPropValueWhereInCids(cidlist);
                //List<string> valueCidList = cidlist.Except(valueWhereInCids).ToList();
                //DownItemPropvalue(valueCidList, worker);

                //List<string> propWhereInCids = ItemPropService.GetPropWhereInCids(cidlist);
                //List<string> propCidList = cidlist.Except(propWhereInCids).ToList();
                //DownItemProp(propCidList, worker);

                //UpdatePropValueIsParent(cidlist, worker);
                //ReturnType type = ItemCatService.UpdateItemCatPropTag(cidlist);
                #endregion

                string cid = threadcidlist[i];
                try
                {
                    UIHelper.DownPropsAndValues(cid, worker);
                }
                catch (Exception ex)
                {
                    if (ciderrorlist == null)
                    {
                        ciderrorlist = new List <string>();
                    }
                    ciderrorlist.Add(cid);
                    worker.ReportProgress(int.Parse(cid), string.Format("异常信息{0}", ex.Message));
                    continue;
                }
                //更新ItemCat中此cid下的属性已完全下载
                ItemCatService.UpdateItemCatPropTag(cid, true);

                /*进度报告*/
                //int percentage = (int)((float)(i + 1) * 100 / (float)times);
                //if (percentage > temp)
                //{
                //    worker.ReportProgress(percentage, cidtask.threadId);
                //}
                //temp = percentage;
                worker.ReportProgress(cidCompleteNum, cidtask.threadId);
            }
            e.Result = cidtask.threadId;
        }