Disappearing System Tray icons - c#

Im creating a system tray application in visual studio 2010, using C#.
When the application starts i create my thread and a system tray icon. THe icon shows, however whenever i mouse over the icon, it disappears ( the application is still running ), and even if i click the button to show all hidden icons, it doesnt display.
However, if i dont try to mouse over on it, then it stays their in the system tray.
Any Thoughts or experience?
Thanks in advance
Thanks for the answers guys.
Uhh, something i did to fix before so although for those who are perhaps curious.
I initially wasnt using a windows form, and this is when the problem occured. However when i set my app to be a windows form, and just hide the form, and not show it in the taskbar, it worked.

Paste this code into your form class:
protected override void OnFormClosing(FormClosingEventArgs e) {
notifyIcon1.Visible = false;
base.OnFormClosing(e);
}
This ensures the icon will disappear without lingering in the tray. Now set a breakpoint on that code and find out why your form is closing. Copy and paste the stack trace into your question if you cannot figure out why.

This means that tray icon has been removed. That usually happens after process terminates but the tray stays there - it is a windows bug.
So for some reason, your tray icon perhaps "crashes".
Without seeing your code, it would be impossible to comment any further.

If you are creating the icon object and letting it go out of scope without any reference to it, the next garbage collection will call it's destructor and this will happens.

When the Windows Explorer restarts ,windows will clear all the icons in the notification area and sends a broadcast message TaskbarCreated .One has to use the message to add the notification icon again .
You can use the following code to listen to the event :
UINT WM_TaskBarCreated = ::RegisterWindowMessage(L"TaskbarCreated");
and the use windowproc or MessageHandler to add the icon back in the notifiation area.

Related

Can't restore minimized WinForms app from taskbar

I have a very strange problem, in which a standard WinForms C# application can sometimes not be restored from the taskbar, after it has been minimized or if another application was used in maximized mode.
This happens on Windows Server 2012 and on Windows 10 (I haven't tested it in other OS'es). If the mouse hovers over my applications taskbar icon, a thumbnail view of my application shows up. Moving the mouse cursor up, to hover over the thumbnail, the application actually shows up on the desktop again, but if I left click on the thumbnail or moves the cursor off the thumbnail, it disappears again. If instead I right click the thumbnail, I can choose "Maximize" or "Restore" from the popup menu, and either works as expected. So the issue only affects regular left clicking on the taskbar icon or the popup thumbnail.
I'm using .NET Framework 4.6 for my application, and the application consists only of a single form with default property values and no WndProc overrides or other fancy things.
I have no idea how to debug this, and the bug is not reproducible 100% of the times, so any suggestions on how I can capture and provide more information to help solve the issue would be very welcome.
For me, the problem was an always visible modeless Form that was owned by the main window. Apparently when the main window is minimized, the modeless form needs to be minimized as well. WinForms doesn't do this automatically for you. I had to subscribe to the main window Resize event, and set the state in there:
private void MainWindow_OnResize(object sender, EventArgs e)
{
modelessForm.WindowState = WindowState;
}
This issue was not encountered on Windows 7, only on Windows 10.

Send window to back when activated

I found the answer to this question in here.
that solution works great when you call the method just once (don't call it from the event window activated). I am creating a gadget and I want the window to always be in the back. if the user clicks on the gadget I don't want it to come to the front which is the default behavior of windows. so what I did in order to solve that problem was to create this event:
private void Window_Activated(object sender, EventArgs e)
{
SendWpfWindowBack(this);
}
so every time the window is activate it call the method founded on the first link that I provided. the problem is that the system tray gets sent to the back. let me show you what I mean.
that is my gadget on visual studio.
when I run it it get's sent to the back: (I open notepad and outlook to illustrate my point)
now when I click on it the event window_Activated fires and it gets send to the back:
But note how the system tray (windows start up menu window) get's sent to the back!!!!
it still is behind everything exept the most important window wich is the windows start up menu. How can I resolve this. why is it going in front of the system tray !?
After 2 hours of stubbornness I figured it out... Since the window was so big for some reason that happen (gadget was bigger than entire desktop). I made it smaller and it worked.

How can I use two NotifyIcons in C# without the second one disappearing when i hover the mouse over?

I Have a VS2008 app that needs to display two notifyIcons in the System tray. One is the main application icon, which allows quick access to the GUI. The second is a "new message" icon, which is displayed when a new message arrives, and hidden when the user double-clicks on it, much like the new Outlook mail message icon.
The problem i am having is the second message icon is hidden whenever the mouse is moved over the system tray. The first icon behaves as expected, and remains in the system tray while the application is running.
Any ideas?
Thanks - this was partly due to windows glitch and a bug in my code.
Seems the icon will not stay visible when showing a baloon tip - it must be forced visible before showing the baloon tip. The icon did not refresh until i moved my mouse over the tray.

Reset Taskbar Flash in C#

I have an application where the taskbar flashes if an event has occurred. This is working perfectly, and was relatively easy to implement using a Win32 API described below:
http://blogs.x2line.com/al/archive/2008/04/19/3392.aspx
However, when I stop the flashing, sometimes the application is stuck in the "highlighted" state in the taskbar. This only gets reset by clicking on the application in the taskbar, minimizing it, then re-maximizing it. Is there a way to clear this from being highlighted without any user interaction?
Maybe instead of flashing it you could put an overlay icon on it - one line of code from C# with the Code Pack. Then when you want to clear it you could take the overlay icon away - again one line of code. Windows 7 only, however.
Can you post the code that you are using to "Stop" the flashing?
Have you also considered using a different flag such as:
// flash until the window comes to the foreground
FLASHW_TIMERNOFG = 12;
You will still need to click on the applicaiton to get the flash to stop, but you should not have to minimize then re-maximize the app to get the flash to stop.
You can include the FlashTaskbar snippet and use the following code
FlashWindow(Form.Handle, FlashMode.FLASHW_STOP)

Application not receiving event when clicked on taskbar

I have a .NET application (C#, WinForms) application running on Windows XP. If i minimize my application, and have several other windows minimized to the taskbar, and click on my application (in the taskbar) then often i see the taskbar "icon" blink but my application fails to "restore" its window. Any suggestions to what might cause this? Any hints on how to check if my application is not getting an event from the mouse-click.
UPDATE: Could anybody give an example of, how to output any incoming events to an application. Something that allows me to e.g. print the received events using Console.Writeline() to see, if my application gets an event when I click on the taskbar?
http://www.catch22.net/software/winspy-17
I venture to guess that your app will become in focus.
AFAIK this should not have anything to do with your application. Is there any other application running which always remains on top?
You dont handle maximising and minimising to and from the taskbar in your app. That is to say you dont have to. Windows deals with this and so this would appear to be in no way related to your app not handling an event, rather Windows doing something (or not doing something).

Categories