private void Progress_LongRunningTaskCompleted(object sender, LongRunningTaskCompletedEventArgs e)
 {
     // Handle errors or cancelled state
     if (e.Error != null)
     {
         MessageBox.Show("Exception occurred: " + e.Error.Message);
     }
     else if (e.Cancelled)
     {
         MessageBox.Show("Operation was cancelled!");
     }
     else
     {
         MessageBox.Show($"Result was: {e.Result}");
     }
 }
        private void PartialResult_LongRunningTaskCompleted(object sender, LongRunningTaskCompletedEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                Example6Started.Content = "Finished";
            });

            // Handle errors or cancelled state
            if (e.Error != null)
            {
                MessageBox.Show("Exception occurred: " + e.Error.Message);
            }
            else if (e.Cancelled)
            {
                MessageBox.Show("Operation was cancelled!");
            }
            else
            {
                MessageBox.Show($"Result was: {e.Result}");
            }
        }
        private void Asynchronous_LongRunningTaskCompleted(object sender, LongRunningTaskCompletedEventArgs e)
        {
            // Required, because this event will not be called inside the UI Thread, so the access to
            // UI elements is not possible.
            Application.Current.Dispatcher.Invoke(() =>
            {
                Example2Started.Content = "Finished";
            });

            // Handle errors or cancelled state
            if (e.Error != null)
            {
                MessageBox.Show("Exception occurred: " + e.Error.Message);
            }
            else if (e.Cancelled)
            {
                MessageBox.Show("Operation was cancelled!");
            }
            else
            {
                MessageBox.Show($"Result was: {e.Result}");
            }
        }