private void State_OnStateChanged(object sender, State.state e) { int num = (int)e; double percent = (double)num / (typeof(State.state).GetEnumValues().Length - 1) * 100; PB_DownloadProgress.Dispatcher.BeginInvoke(new Action(() => PB_DownloadProgress.SetPercent(percent, 0.5f))); if (e == State.state.Ready || e == State.state.Default) { switch (e) { case State.state.Default: btn_Patcher.Dispatcher.BeginInvoke(new Action(() => btn_Patcher.Content = "Download Patches")); break; case State.state.Ready: btn_Patcher.Dispatcher.BeginInvoke(new Action(() => btn_Patcher.Content = "Launch WoW")); break; } btn_Patcher.Dispatcher.BeginInvoke(new Action(() => btn_Patcher.IsEnabled = true)); } else { btn_Patcher.Dispatcher.BeginInvoke(new Action(() => btn_Patcher.Content = e)); btn_Patcher.Dispatcher.BeginInvoke(new Action(() => btn_Patcher.IsEnabled = false)); } }
public async void Test() { await Task.Run(async() => { for (int i = 0; i <= 100; i++) { await PB_DownloadProgress.Dispatcher.BeginInvoke(new Action(() => PB_DownloadProgress.SetPercent(i, 0.5f))); await Task.Delay(100); } }); }