예제 #1
0
        public static InfoWindow Create(string title, string text, string image_url, string action_name, Action action)
        {
            lock (lock_object)
            {
                InfoWindow w = null;

                Action a = () =>
                {
                    w = new InfoWindow(title, text, image_url, action_name, action);
                    WindowInteropHelper h = new WindowInteropHelper(w);
                    h.EnsureHandle();
                    w.Show();
                    ThreadRoutines.StartTry(() =>
                    {
                        Thread.Sleep(Settings.Default.InfoToastLifeTimeInSecs * 1000);
                        w.BeginInvoke(() => { w.Close(); });
                    });
                    if (!string.IsNullOrWhiteSpace(Settings.Default.InfoSoundFile))
                    {
                        SoundPlayer sp = new SoundPlayer(Settings.Default.InfoSoundFile);
                        sp.Play();
                    }
                };

                lock (ws)
                {
                    if (dispatcher == null)
                    {//!!!the following code does not work in static constructor because creates a deadlock!!!
                        ThreadRoutines.StartTry(() =>
                        {
                            //this window is used to hide notification windows from Alt+Tab panel
                            invisible_owner_w               = new Window();
                            invisible_owner_w.Width         = 0;
                            invisible_owner_w.Height        = 0;
                            invisible_owner_w.WindowStyle   = WindowStyle.ToolWindow;
                            invisible_owner_w.ShowInTaskbar = false;
                            invisible_owner_w.Show();
                            invisible_owner_w.Hide();

                            dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
                            System.Windows.Threading.Dispatcher.Run();
                        }, null, null, true, ApartmentState.STA);
                        if (!SleepRoutines.WaitForCondition(() => { return(dispatcher != null); }, 3000))
                        {
                            throw new Exception("Could not get dispatcher.");
                        }
                    }
                }
                dispatcher.Invoke(a);
                return(w);
            }
        }
예제 #2
0
 protected override void Deleting()
 {
     if (w != null)
     {
         w.Invoke(() =>
         {
             try
             {
                 w.Close();
             }
             catch { }
             w = null;
         });
     }
 }