public static void ShowWindow(TimeSpan initialDelay, CancellationToken token)
        {
            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();

                token.Register(() => wnd.Dispatcher.BeginInvoke(new Action(wnd.Close)));
                (new Application()).Run(wnd);
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Пример #2
0
        public static void ShowWindow(TimeSpan initialDelay, CancellationToken token, ProgressSource progressSource)
        {
            var thread = new Thread(() => {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                try {
                    Task.Delay(initialDelay, token).ContinueWith(_ => { return(true); }).Wait();
                } catch (Exception) {
                    // NB: Cancellation will end up here, so we'll bail out
                    return;
                }

                var wnd = new AnimatedGifWindow();
                wnd.Show();

                token.Register(() => wnd.Invoke(new Action(() => wnd.Close())));

                var t       = new System.Windows.Forms.Timer();
                var taskbar = TaskbarManager.Instance;
                t.Tick     += (o, e) => {
                    wnd.WindowState = FormWindowState.Normal;
                    taskbar.SetProgressState(TaskbarProgressBarState.Normal, wnd.Handle);

                    progressSource.Progress += (_o, val) => {
                        if (wnd.IsDisposed)
                        {
                            return;
                        }
                        wnd.Invoke(new Action(() => taskbar.SetProgressValue(val, 100, wnd.Handle)));
                    };

                    t.Stop();
                };

                t.Interval = 400;
                t.Start();

                Task.Delay(TimeSpan.FromSeconds(5.0), token).ContinueWith(task => {
                    if (task.IsCanceled)
                    {
                        return;
                    }
                    if (wnd.IsDisposed)
                    {
                        return;
                    }
                    wnd.Invoke(new Action(() => wnd.TopMost = false));
                });

                Application.Run(wnd);
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Пример #3
0
        public static void ShowWindow(TimeSpan initialDelay, CancellationToken token, ProgressSource progressSource)
        {
            var wnd = default(AnimatedGifWindow);

            var thread = new Thread(() => {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                if (!Equals(initialDelay, TimeSpan.Zero))
                {
                    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();
        }
        public static void ShowWindow(TimeSpan initialDelay, CancellationToken token)
        {
            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();

                token.Register(() => wnd.Dispatcher.BeginInvoke(new Action(wnd.Close)));
                (new Application()).Run(wnd);
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
        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();
        }
Пример #6
0
 public static void ShowWindow(TimeSpan initialDelay, CancellationToken token, ProgressSource progressSource)
 {
     AnimatedGifWindow wnd     = null;
     Thread            thread1 = new Thread(delegate {
         if (!token.IsCancellationRequested)
         {
             EventHandler <int> < > 9__5;
             Action < > 9__4;
             Action <Task> < > 9__2;
             try
             {
                 Task.Delay(initialDelay, token).ContinueWith <bool>(t => true).Wait();
             }
             catch (Exception)
             {
                 return;
             }
             wnd = new AnimatedGifWindow();
             wnd.Show();
             Action <Task> continuationAction = < > 9__2;
             if (< > 9__2 == null)
             {
                 Action <Task> local3 = < > 9__2;
                 continuationAction   = < > 9__2 = delegate(Task t) {
                     if (!t.IsCanceled)
                     {
                         Action < > 9__3;
                         Action method = < > 9__3;
                         if (< > 9__3 == null)
                         {
                             Action local1 = < > 9__3;
                             method        = < > 9__3 = () => wnd.Topmost = false;
                         }
                         wnd.Dispatcher.BeginInvoke(method, new object[0]);
                     }
                 };
             }
             Task.Delay(TimeSpan.FromSeconds(5.0), token).ContinueWith(continuationAction);
             Action callback = < > 9__4;
             if (< > 9__4 == null)
             {
                 Action local4 = < > 9__4;
                 callback      = < > 9__4 = () => wnd.Dispatcher.BeginInvoke(new Action(wnd.Close), new object[0]);
             }
             token.Register(callback);
             EventHandler <int> handler3 = < > 9__5;
             if (< > 9__5 == null)
             {
                 EventHandler <int> local5 = < > 9__5;
                 handler3 = < > 9__5 = (sender, p) => wnd.Dispatcher.BeginInvoke(() => wnd.get_TaskbarItemInfo().set_ProgressValue(((double)p) / 100.0), new object[0]);
             }
             EventHandler <int> handler = handler3;
             progressSource.Progress   += handler;
             try
             {
                 new Application().Run(wnd);
             }
             finally
             {
                 progressSource.Progress -= handler;
             }
         }
     });