The taskbar icon for my app is missing sometimes when my app auto starts upon user logon

I have a WPF app that I wrote in C# that creates a taskbar icon when it is launched. The only UI for the app that the user will usually see is the menu that appears if they right click on the taskbar icon. In other words, there is no "main window" that appears when launching the app. I have the app setup to automatically launch when my Windows user logs into Windows. Most of the time this works correctly in the sense that my app starts up and the taskbar icon gets successfully created. Once in a while though my app will start (i.e. I will see the .exe if I look using the Task Manager) but the taskbar icon will not be present at all and I do not receive an error message. When this happens there is no way to interact with the app and I have to kill it using Task Manager and then manually re-launch it at which point the taskbar icon will show up correctly. This failure of the taskbar icon to appear seems to only happen when the app is being launched automatically when the user logs in. In other words, if I instead log into my Windows user, then wait a minute or so, and then manually launch my app then the taskbar icon always successfully appears. Right now I am working around this problem by using the Task Scheduler to launch my app with a few minute delay, but I do not want to solve the problem this way. Solving the problem this way causes a few annoyances... #1 is that I have to intentionally over-estimate the amount to time to wait before launching my app so that I make sure to wait long enough but then I can't interact with my app right away... #2 is related in that if I run my app in a VM I have no realistic way to know how long it will take for Windows to become "ready" to create taskbar icons so I have to over-estimate the amount of time to wait before launching my app by even longer... #3 is that I have to remember to set this delay time for each computer/user I setup my app on.
1 Reply
PurplePeopleEater
Also, as a side note, I have other apps I have written in AutoIT that also exhibit this behavior of sometimes failing to create their taskbar icons when being autorun during user login. It is as though sometimes when my C# app (and my AutoIT apps) launch Windows happens to be ready to create taskbar icons in which case my taskbar icons get created successfully and other times Windows happens to not be ready to create taskbar icons yet and in that case my apps can't create their taskbar icons. Questions: 1) Is there a way to capture the fact that creating the taskbar icon has failed so that I can try again after a few seconds? 2) In lieu of being able to do #1, is there a way for me to programmatically check to see that Windows is "ready" in general or that it has completed loading the Windows user so that I can wait for this to happen before trying to create my taskbar icon? If so, what event should I be waiting for? 3) Any other ideas that I might not be thinking of? Thank you in advance for any help! bump