private async void Form1_Load(object sender, EventArgs e) { var hotelsCrawler = new StrongCrawler(); hotelsCrawler.OnStrart += hotelsCrawler_OnStrart; hotelsCrawler.OnError += hotelsCrawler_OnError; hotelsCrawler.OnCompleted += hotelsCrawler_OnCompleted; var cityUrl = "http://hotels.ctrip.com/cityList"; Operation op = new Operation(); await hotelsCrawler.Start(new Uri(cityUrl), null, op); }
private async void cityListBox_DoubleClick(object sender, EventArgs e) { await Task.Delay(300); var cityUrl = cityListBox.SelectedValue as Uri; var cityName = cityListBox.Text; var hotelListCrawler = new StrongCrawler(); hotelListCrawler.OnStrart += delegate { Console.WriteLine("开始搜索" + cityName); }; hotelListCrawler.OnError += (s, arg) => { Console.WriteLine("搜索发生错误:" + arg.ex); }; hotelListCrawler.OnCompleted += hotelListCrawler_OnCompleted; this.cityListBox.Enabled = false; await hotelListCrawler.Start(cityUrl, null, new Operation()); this.cityListBox.Enabled = true; }