private async void Button_Click_2(object sender, RoutedEventArgs e) { var p = PendingBoxX.Show("正在连接网络..."); try { var url = "https://gitee.com/free2048/textfilter/raw/master/keywords"; p.UpdateMessage("正在下载敏感词库...\n请勿用于违规途径,否则追究法律责任。"); var cc = await new HttpClient().GetAsync(url); var str = await cc.Content.ReadAsStringAsync(); p.UpdateMessage("获取内容...\n请勿用于违规途径,,否则依法追究责任"); var file = System.IO.Path.Combine(MenuCaller.api.AppDirectory, "Keywords", "words.txt"); if (!File.Exists(file)) { File.Create(file).Close(); } File.WriteAllText(file, str); p.UpdateMessage("内容获取完成,写出文件成功!...\n请勿用于违规途径,,否则依法追究责任"); await Task.Delay(2000); p.Close(); } catch (Exception ex) { p.UpdateMessage("失败...请联系开发解决问题\n" + "问题原因:" + ex.Message); } }
/// <summary> /// 异步载入窗口数据时显示加载窗口 /// </summary> private void RunTaskMethod() { try { var PendingBox = PendingBoxX.Show("正在加载武器数据,请稍等。", "Loading~", this); var task = Task.Factory.StartNew(() => WeaponAndSkill.LoadWeaponPanelSimulator()); var act = new Action(() => { try { while (true) { if (!task.IsCompleted) { continue; } var excelReader = task.Result; if (excelReader.HasError) { throw new Exception(excelReader.ErrorMsg); } Fc.GetSearchTipList(excelReader.WeaponList.ObjList); WeaponSkillList.AddRange(excelReader.SkillList.ObjList); WeaponSkillNameList.AddRange(excelReader.SkillList.ObjList.GroupBy(x => x.Extra_Description + x.Main_Description).Select(x => x.Key).ToList()); PendingBox.Close(); return; } } catch (Exception ex) { MessageBoxX.Show("子线程错误:" + ex.Message, "ErrorMessage", MessageBoxButton.OK, MessageBoxIcon.Error); Application.Current.Dispatcher.Invoke(new Action(this.Close)); } }); var thread = new Thread(new ThreadStart(act)); thread.Start(); } catch (Exception ex) { MessageBoxX.Show("打开窗口时发生错误:" + ex.Message, "ErrorMessage", MessageBoxButton.OK, MessageBoxIcon.Error); this.Close(); } }
public async void PendingBox(string cap) { IPendingHandler handler = null; switch (cap) { case "normal": handler = PendingBoxX.Show("Processing .....", "Normal", true, Application.Current.MainWindow); break; } if (handler != null) { handler.Cancelling += Handler_Cancelling; await Task.Delay(2000); handler.UpdateMessage("Almost complete ..."); await Task.Delay(4000); handler.Close(); } }