c# – Blinking taskbar window

Question:

Can you please tell me how to make the window blink in the taskbar? Well, they often do like some kind of event in the window happened, but it is minimized and here is such a notification.

@VladD xs I may be doing something wrong, but I just don't want it to work. I put a breakpoint on me when trying to create an instance of WindowInteropHelper exits the function altogether. I test like 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);
    }
}

Answer:

Try this:

[DllImport("user32.dll")]
public static extern int FlashWindow(IntPtr Hwnd, bool Revert);

// ...
var hwnd = new WindowInteropHelper(window).Handle;
FlashWindow(hwnd, true);

It is not worth calling this function on the timer, since it delivers messages to an unknown stream. Use a DispatcherTimer , it executes events on 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();
Scroll to Top