protected override void Deleting()
 {
     if (w != null)
     {
         w.Invoke(() =>
         {
             try
             {
                 w.Close();
             }
             catch { }
             w = null;
         });
     }
 }
        public static AlertWindow Create(string title, string text, string image_url, string action_name, Action action)
        {
            lock (lock_object)
            {
                Action a = () =>
                {
                    if (This != null)
                    {
                        try
                        {//might be closed already
                            This.Close();
                        }
                        catch
                        { }
                    }

                    if (invisible_owner_w == null)
                    {
                        //this window is used to hide notification windows from Alt+Tab panel
                        invisible_owner_w             = new Window();
                        invisible_owner_w.WindowStyle = WindowStyle.ToolWindow;
                        invisible_owner_w.Width       = 0;
                        invisible_owner_w.Height      = 0;
                        //invisible_owner_w.Width = SystemParameters.FullPrimaryScreenWidth;
                        //invisible_owner_w.Height = SystemParameters.FullPrimaryScreenHeight;
                        //invisible_owner_w.AllowsTransparency = true;
                        //invisible_owner_w.Background = Brushes.Transparent;
                        //invisible_owner_w.Topmost = true;
                        invisible_owner_w.ShowInTaskbar = false;
                        invisible_owner_w.Top           = 0;
                        invisible_owner_w.Left          = 0;
                        //invisible_owner_w.MouseDown += delegate
                        //{
                        //    invisible_owner_w.Hide();
                        //};
                        //invisible_owner_w.KeyDown += delegate
                        //{
                        //    invisible_owner_w.Hide();
                        //};

                        invisible_owner_w.Show();
                        invisible_owner_w.Hide();
                    }

                    This = new AlertWindow(title, text, image_url, action_name, action);
                    //ElementHost.EnableModelessKeyboardInterop(This);
                    WindowInteropHelper wih = new WindowInteropHelper(This);
                    This.handle = wih.EnsureHandle();
                    This.Owner  = invisible_owner_w;
                    This.Show();
                    //ThreadRoutines.StartTry(() =>
                    //{
                    //    Thread.Sleep(Settings.Default.InfoWindowLifeTimeInSecs * 1000);
                    //    This.BeginInvoke(() => { This.Close(); });
                    //});
                    if (!string.IsNullOrWhiteSpace(Settings.Default.InfoSoundFile))
                    {
                        SoundPlayer sp = new SoundPlayer(Settings.Default.AlertSoundFile);
                        sp.Play();
                    }
                };

                if (dispatcher == null)
                {//!!!the following code does not work in static constructor because creates a deadlock!!!
                    ThreadRoutines.StartTry(() =>
                    {
                        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);

                //ControlRoutines.InvokeFromUiThread(a);

                return(This);
            }
        }
 internal override void Activate()
 {
     Deleting();
     w = AlertWindow.Create(Title, Text, ImageUrl, ActionName, Action);
 }