示例#1
0
        private async void button2_ClickAsync(object sender, EventArgs e)
        {
            button2.Enabled = false;
            List <Area> areas = arearepsository.GetEntity(p => p.Url != string.Empty).ToList();

            try
            {
                List <Task> tasks   = new List <Task>();
                TaskFactory factory = new TaskFactory();
                foreach (var item in areas)
                {
                    tasks.Add(factory.StartNew(() =>
                    {
                        CrawlShop shop = new CrawlShop();
                        shop.CrawlAll(item);
                    }));
                    if (tasks.Count > 1)
                    {
                        tasks = tasks.Where(t => !t.IsCompleted && !t.IsCanceled && !t.IsFaulted).ToList();
                        Task.WaitAny(tasks.ToArray());
                        Console.WriteLine(tasks.Count() + "Go  on---------------");
                    }
                }
                Task.WaitAll(tasks.ToArray());
                Console.WriteLine("Over");
                button2.Enabled = true;
            }
            catch (Exception exception)
            {
                button2.Enabled = true;
                log.Error(exception.ToString());
            }
        }
示例#2
0
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Area area = arearepsository.GetEntity(p => p.Id == int.Parse(SelectId)).FirstOrDefault();

            try
            {
                CrawlShop shop = new CrawlShop();
                shop.CrawlAll(area);
            }
            catch (Exception exception)
            {
                log.Error(exception.ToString());
            }
        }