Can you please tell me how to make the window blink in the taskbar? Well, so often they do some kind of event in the window, it happened, but it is minimized and this is the notice.

@VladD xs I may be doing something wrong, but I just don’t want to work with it. I put a breakpoint when I try to create an instance of WindowInteropHelper exiting the function altogether. I'm testing this:

public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var t = new Timer(5000); t.Elapsed += Elapsed; t.Start(); } [DllImport("user32.dll")] public static extern int FlashWindow(IntPtr Hwnd, bool Revert); private void Elapsed(object sender, ElapsedEventArgs e) { var hwnd = new WindowInteropHelper(this).Handle; FlashWindow(hwnd, true); } } 
  • And just window.Activate() will not drive? (The window with this should be in the background.) - VladD
  • @VladD Even nothing from calling this function happens. - PECHAIRMINE
  • And the window at the same time in the background? - VladD
  • @VladD what does the background mean? Minimized? Yes collapsed. - PECHAIRMINE
  • More precisely, perhaps I meant blinking not in the tray, but in the taskbar. A bit confused concepts. - PECHAPTER

1 answer 1

Try this:

 [DllImport("user32.dll")] public static extern int FlashWindow(IntPtr Hwnd, bool Revert); // ... var hwnd = new WindowInteropHelper(window).Handle; FlashWindow(hwnd, true); 

Calling this function on the timer is not worth it, because it delivers messages in a stream that is unclear. Use DispatcherTimer , it executes events in the main thread:

 var dt = new DispatcherTimer(); dt.Tick += (s, e) => { dt.Stop(); var hwnd = new WindowInteropHelper(this).Handle; FlashWindow(hwnd, true); }; dt.Interval = TimeSpan.FromSeconds(5); dt.Start();