Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- WindowStartupLocation = WindowStartupLocation.CenterScreen;
- InitializeComponent();
- }
- private void LoginButton_Click(object sender, RoutedEventArgs e)
- {
- LoginButton.IsEnabled = false;
- var task = Task.Run(() => {
- Thread.Sleep(2000);
- return "Login Successful!";
- });
- task.ContinueWith((t) => {
- if (t.IsFaulted)
- {
- Dispatcher.Invoke(() =>
- {
- LoginButton.Content = "Login failed!";
- LoginButton.IsEnabled = true;
- });
- }
- else
- {
- Dispatcher.Invoke(() =>
- {
- LoginButton.Content = t.Result;
- LoginButton.IsEnabled = true;
- });
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement