private void TimerTick(object sender, EventArgs e) { if (Task.IsCompleted || Task.IsCanceled || Task.IsFaulted) { Close(); } if (Cancelled) { ((this.FindName("Text")) as TextBlock).Text = "Cancelling ..."; } else { var data = ProgressTracker.GetCurrentProgress(); if (data.MaxProgress != 0) { Percent.Visibility = Visibility.Visible; Percent.Text = Math.Max(Math.Min(1, (data.CurrentProgress / data.MaxProgress)), 0).ToString("P"); } if (!String.IsNullOrWhiteSpace(data.ProgressInfo)) { ((this.FindName("Text")) as TextBlock).Text = data.ProgressInfo; } } }