private void BtnChange_Click(object sender, RoutedEventArgs e) { int index = LvwAttacks.SelectedIndex; if (index == -1) { return; } changeAttack = new NewAttack(villList) { Time = attacks[index].Time, Src = attacks[index].Src, Dest = attacks[index].Dest, Army = attacks[index].Army }; changeAttack.Owner = this; changeAttack.Done += (s1, e1) => { attacks[index].Time = changeAttack.Time; attacks[index].Src = changeAttack.Src; attacks[index].Dest = changeAttack.Dest; attacks[index].Army = changeAttack.Army; attacks.Sort(); refreshID(attacks); LvwAttacks.Items.Refresh(); }; changeAttack.ShowDialog(); }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { BackgroundWorker work = new BackgroundWorker(); #region work.ProgressChanged work.ProgressChanged += (s1, e1) => { addLog(e1.UserState as string); }; #endregion work.DoWork += GetListVillages; #region work.RunWorkerCompleted work.RunWorkerCompleted += (s1, e1) => { villList = (List <Village>)e1.Result; newAttack = new NewAttack(villList); newAttack.Owner = this; newAttack.Done += (s2, e2) => { if (attacks == null) { attacks = new List <AttackPlanner>(); LvwAttacks.ItemsSource = attacks; } attacks.Add(new AttackPlanner() { Time = e2.DateTime, Src = e2.Src, Dest = e2.Dest, Army = e2.Army }); attacks.Sort(); refreshID(attacks); LvwAttacks.Items.Refresh(); }; newAttack.ShowDialog(); }; #endregion work.WorkerReportsProgress = true; work.RunWorkerAsync(); } //multithreading