Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 592761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:46:26+00:00 2026-05-13T15:46:26+00:00

Short version : I think I need help with properly using events in PowerShell

  • 0

Short version: 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.

Long Version:

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.

I was able to create a Write-BalloonTip script (below) that does roughly what I want. The only problem is that, as sometimes happens with tray icons, the tray icon doesn’t disappear until I mouse over it. By re-using the same global variable to represent the NotifyIcon, 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 BalloonTipClosed 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.

The annoying part is that a simple .Dispose seems to work on subsequent calls of the script, leading me to think that the event script block isn’t being called at all.

I’ve verified that BalloonTipClosed gets called after the tip fades away in a separate WinForms app.

Am I missing something basic? Any help is much appreciated. Thanks!

Here’s the code for “Write-BalloonTip.ps1”:

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:46:26+00:00Added an answer on May 13, 2026 at 3:46 pm

    I think you need to execute this code in an STA thread. PowerShell (v2 shown here) executes in an MTA thread by default:

    PS U:\> [System.Threading.Thread]::CurrentThread
    
    
    ManagedThreadId    : 5
    ExecutionContext   : System.Threading.ExecutionContext
    Priority           : Normal
    IsAlive            : True
    IsThreadPoolThread : False
    IsBackground       : False
    ThreadState        : Running
    ApartmentState     : MTA
    CurrentUICulture   : en-US
    CurrentCulture     : en-US
    Name               : Pipeline Execution Thread
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: I have a similar setup to StackOverflow. Users get Achievements. I have
Ok, long story short I have a Windows service that handles Win32_VolumeChangeEvent and logs
Suppose I need to track my clicks using google analytics scripts. I know that
Short version : I have a working solution using a UISegmentedControl but I don't
Short version : does Android reboot the phone (literally reboot) to get rid of
Short version: Can I grant access to external databases to a role? Long version:
Short version : I would like the maven-glassfish-plugin to only be executed in the
Short Version: I'm looking for a technique to keep nearly-sorted data in nearly-sorted order
Short version: In pure Java EE 6, is there something like Spring's Authentication Processing
Short version : echo testing | vim - | grep good This doesn't work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.