catch notifyicon kill attempt so dispose can run

D

deciacco

I have a NotifyIcon application. (c# 2) I want to be able to catch a
kill/shutdown attempt so that I can call Dispose() to remove the icon. I
tried to create an event handler for ApplicationExit and put my icon
dispose call in there, but when process.kill() is called from an outside
app on the notifyicon app, the event doesn't get raised. the app closes
but the icon remains in the tray as dispose was never called.

any ideas?

another way of telling the notifyicon class that it needs to close?


Thanks.
 
B

Ben Voigt [C++ MVP]

deciacco said:
I have a NotifyIcon application. (c# 2) I want to be able to catch a
kill/shutdown attempt so that I can call Dispose() to remove the icon. I
tried to create an event handler for ApplicationExit and put my icon
dispose call in there, but when process.kill() is called from an outside
app on the notifyicon app, the event doesn't get raised. the app closes but
the icon remains in the tray as dispose was never called.

any ideas?

another way of telling the notifyicon class that it needs to close?

If TerminateProcess is called, which I guess is what Process.Kill probably
does, *no more code in the targetted process gets to run*. I just had to
work around this problem myself (process being killed, not using NotifyIcon)
and did so by having another process waiting on the process handle of the
first which is signalled when the process ends for any reason, triggering my
cleanup. Not sure how or even if you can do out-of-process cleanup with
shell notification icons though.
 
B

Ben Voigt [C++ MVP]

deciacco said:
I have a NotifyIcon application. (c# 2) I want to be able to catch a
kill/shutdown attempt so that I can call Dispose() to remove the icon. I
tried to create an event handler for ApplicationExit and put my icon
dispose call in there, but when process.kill() is called from an outside
app on the notifyicon app, the event doesn't get raised. the app closes but
the icon remains in the tray as dispose was never called.

any ideas?

another way of telling the notifyicon class that it needs to close?

To follow up to my previous message -- the shell itself should wait on the
process handle for each process that has one or more tray icons, and remove
them if the process terminates. That it does not could be considered a bug.
Right now the icon is detected as an orphan and removed the next time the
user interacts with it in any way, like moving the mouse over it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top