vb.net - programs' systray icon remains after program stops running in some cases -


i have (vb.net) program creates systray icon when launched.

when exits systray icon removed correctly.

however, in cases, example when program 'end tasked' using ms task manager program's systray icon remains.

this presents unfortunate illusion program still running when not.

however, in these situations, once user moves mouse on program's systray icon program's systray icon disappears.

is there anyway ensure systray icon removed in cases?

when application killed ("end tasked"), don't chance tidy first. app removed memory, , there's no warning (or way prevent it). it's having hole in ground appear beneath feet - don't chance call home goodbye spouse or significant other first. you're gone.)

for other problems (the occasional "phantom icon" remains after app closed properly), there solution. i'm not sure how it's resolved using .net, plain old winapi programming can use postmessage send window wm_null message when application exits cause system tray refresh icons, causes phantom icon disappear.

i've never done in .net, quick check of pinvoke shows should work (untested, compiles , executes in vb.net via vs express 2012 - didn't write actual systray app test whether works or not, because causing "phantom icon" appear intentionally difficult):

private declare function postmessage _     lib "coredll.dll" (byval hwnd intptr, _     byval msg integer, _     byval wparam integer, _     byval lparam integer) intptr  private sub form1_formclosed(sender object, _                              e formclosedeventargs) _                              handles mybase.formclosed     const wm_null integer = &h0     postmessage(me.handle, wm_null, 0, 0) end sub 

note it's extremely important use postmessage , not sendmessage purpose. first places message in message queue , returns, while second waits response (and app won't there send one, it's in process of closing).

note #2: may need in form1_formclosing handler instead of formclosed; said, don't have systray application use test timing of proper place use posting message.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -