Home General

Mechanism to bring attention to LINQPad window and tab?

I have some scripts that are very long running (we're talking days) intended to check a resource and synchronize locally. Most of the time, it is able to run with no problems but occasionally, it will require user interaction.

Is there a mechanism that I can use to "notify" the Linqpad window, or more specifically, a specific script?

I'm thinking, flash the icon, the toolbar, maybe show the name of the script in the title flashing. Maybe a notification in the tool tray perhaps?

Comments

  • Util.HostWindowHandle will give you the handle of the main Linqpad UI program so if you could use PInvoke

    [DllImport("user32.dll")]
    public static extern bool SetForegroundWindow(IntPtr WindowHandle);
    

    Then when you call

    SetForegroundWindow(Util.HostWindowHandle);

    It will flash the LinqPad taskbar.

    You could also call

        if (Util.CurrentQueryPath != null)
            Util.OpenQuery(Util.CurrentQueryPath);
    

    and (providing your query had been saved as least once), then it would switch to the correct query, but that is probably a bad idea in case you happen to be typing in another query at that time.

    It would also be fair simple to send a ToastNotification, but I'm not sure if it could actually capture any actions from it.

  • edited April 21

    SetForegroundWindow steals keyboard focus, which might be an annoyance:

    Brings the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user. The system assigns a slightly higher priority to the thread that created the foreground window than it does to other threads.

    FlashWindow can be used instead.

  • SetForegroundWindow steals keyboard focus, which might be an annoyance:

    Are you sure? I thought that behaviour was changed years ago and if you are working in another window, it flashed the taskbar icon instead. (A quick test shows if have notepad open it doesn't lose the focus when the taskbar flashes)

    FlashWindow can be used instead.

    Actually that's probably better anyway as it will work if the focus is in another query in LinqPad whereas SetForegroundWindow won't.

  • edited April 22

    More on SetForegroundWindow.

Sign In or Register to comment.