Note that there are some explanatory texts on larger screens.

plurals
  1. POProperly displaying a tray balloon tooltip in PowerShell
    primarykey
    data
    text
    <p><strong>Short version</strong>: I think I need help with properly using events in PowerShell that are invoked as a result of a Windows Message to get rid of a balloon tooltip's icon.</p> <p><strong>Long Version</strong>:</p> <p>I have a long-running PowerShell command (a build) that I would like to be notified when it completes via a balloon tooltip in the system tray/notification area.</p> <p>I was able to create a Write-BalloonTip script (below) that does roughly what I want. The only problem is that, <a href="https://stackoverflow.com/questions/1067844/issue-with-notifyicon-not-dissappearing-on-winforms-app">as sometimes happens with tray icons</a>, the tray icon doesn't disappear until I mouse over it. By re-using the same global variable to represent the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx" rel="nofollow noreferrer">NotifyIcon</a>, I'm able to re-use this script and keep it so that only one system tray icon remains (until I mouse over it). This still feels like a hack. I tried to add an event handler so that it'd be notified on the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.balloontipclosed.aspx" rel="nofollow noreferrer">BalloonTipClosed</a> event and then dispose of it there. In the event handler, I tried all three techniques I've seen suggested for getting rid of the lingering icon to no avail. </p> <p>The annoying part is that a simple <code>.Dispose</code> seems to work on subsequent calls of the script, leading me to think that the event script block isn't being called at all.</p> <p>I've verified that BalloonTipClosed gets called after the tip fades away in a separate WinForms app.</p> <p>Am I missing something basic? Any help is much appreciated. Thanks!</p> <p>Here's the code for "Write-BalloonTip.ps1":</p> <pre><code>param ( $text, $title = "", $icon = "Info", $timeout=15000 ) [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | out-null if ($global:writeBalloonTipIcon) { # This gets rid of the previous one $global:writeBalloonTipIcon.Dispose() } $global:writeBalloonTipIcon = new-object System.Windows.Forms.NotifyIcon $global:writeBalloonTipIcon.Icon = [System.Drawing.SystemIcons]::Information # FIXME: This *should* cleanup the icon after it's done, but it doesn't seem to work $global:writeBalloonTipIcon.add_BalloonTipClosed( { # this *should* work, but it's not. What am I missing? $global:writeBalloonTipIcon.Icon = $null; $global:writeBalloonTipIcon.Visible = $false; $global:writeBalloonTipIcon.Dispose(); }); $global:writeBalloonTipIcon.Visible = $true; $global:writeBalloonTipIcon.ShowBalloonTip($timeout, $title, $text, $icon); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload