/*------------------------------------------------------------------------- // UNCLASSIFIED /*------------------------------------------------------------------------- RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON COMPANY. THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT. UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY. -------------------------------------------------------------------------*/ using System; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Threading; namespace ProgramLib.GUI.View { /// /// Interaction logic for WaitWindow.xaml /// internal partial class WaitWindow : Window { private DispatcherTimer _timer; private int _delayMs; private const int _timerTickIntervalMs = 25; private DateTime _startDateTime; public WaitWindow(string message, double delaySec) { InitializeComponent(); Uri iconUri = new Uri($"pack://application:,,,/{GetType().Assembly.GetName().Name};component/Resources/Icons/app.ico"); this.Icon = BitmapFrame.Create(iconUri); WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; tbMessage.Text = message; _delayMs = (int)(delaySec * 1000.0); _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(_timerTickIntervalMs); _timer.Tick += new EventHandler(Timer_Tick); _timer.Start(); _startDateTime = DateTime.Now; } private void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { DragMove(); } protected override void OnContentRendered(EventArgs e) { base.OnContentRendered(e); // Content of window may be black in case of SizeToContent is set. // This eliminates the problem. // Do not use InvalidateVisual because it may implicitly break your markup. InvalidateMeasure(); } /// /// Show count down timer /// private void Timer_Tick(object sender, EventArgs e) { TimeSpan ts = DateTime.Now - _startDateTime; int remainingMs = _delayMs - (int)ts.TotalMilliseconds; if (remainingMs >= 0) { TimeSpan ts2 = TimeSpan.FromMilliseconds(remainingMs); tbCountDownTimer.Text = String.Format(@"{0:mm\:ss\.ff}", ts2); } else { _timer.Stop(); this.Close(); } } } }