static void Main() { var animatedGifWindowToken = new CancellationTokenSource(); var progressSource = new ProgressSource(); AnimatedGifWindow.ShowWindow(TimeSpan.FromSeconds(1), animatedGifWindowToken.Token, progressSource); Task.Delay(TimeSpan.FromMinutes(5)).Wait(); animatedGifWindowToken.Cancel(); }
public static void ShowWindow(TimeSpan initialDelay, CancellationToken token, ProgressSource progressSource) { var wnd = default(AnimatedGifWindow); var thread = new Thread(() => { if (token.IsCancellationRequested) { return; } try { Task.Delay(initialDelay, token).ContinueWith(t => { return(true); }).Wait(); } catch (Exception) { return; } wnd = new AnimatedGifWindow(); wnd.Show(); Task.Delay(TimeSpan.FromSeconds(5.0), token).ContinueWith(t => { if (t.IsCanceled) { return; } wnd.Dispatcher.BeginInvoke(new Action(() => wnd.Topmost = false)); }); token.Register(() => wnd.Dispatcher.BeginInvoke(new Action(wnd.Close))); EventHandler <int> progressSourceOnProgress = ((sender, p) => wnd.Dispatcher.BeginInvoke( new Action(() => wnd.TaskbarItemInfo.ProgressValue = p / 100.0))); progressSource.Progress += progressSourceOnProgress; try { (new Application()).Run(wnd); } finally { progressSource.Progress -= progressSourceOnProgress; } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }