Reputation: 3135
Update: Issue appears to be introduced with .NET 4.5.2. Problem does not occur with either 4.5.1 or 4.5.
I have a strange issue I am having difficulty debugging. We have a WPF application built on top of the NotifyIcon made by Philipp Sumi. http://www.codeproject.com/Articles/36468/WPF-NotifyIcon http://www.hardcodet.net/wpf-notifyicon
We are using the verion from nugget:
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.5" targetFramework="net45" />
The problem is that the first time (and only the first time) the application is ran, it fails with the following exception. It is easy to recreate by hovering the mouse over the system tray icon when it appears. On subsequent runs there is no problem. The application does not have any saved state or persistent data. I'm not aware of any difference between the first and subsequent runs. It does however start much faster the second time. The same problem occurs in the windowless example application that comes with NotifyIcon.
Upvotes: 7
Views: 3276
Reputation: 622
My solution was to remove icon to null. Removing this solved the same problem as described in the question. Even though the line was in Window_Closing the app crached on startup.
internal System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
....
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
ni.Icon = Null;
}
Now I hide the icon on Window_Closing using: (Otherwise the icon stays in the nitification area)
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
ni.Visible = false;
}
BTW: Using the "ToolTip-solution" added more the 10 sek startup time to my app.
Upvotes: 0
Reputation: 314
I have the same problem. Unfortunately I'm not able to reproduce that behaviour but I have another program which uses this library, which works fine. So the main difference is that the working program is not only using the ToolTipText property in the XAML part but also provides a UIElement for the TrayToolTip property.
<hc:TaskbarIcon.TrayToolTip>
<CustomUIElement/>
</hc:TaskbarIcon.TrayToolTip>
So maybe this could be an alternative workaround.
(Sorry for all the cancelled comments, just figured out that code blocks are not supported in comments)
Upvotes: 0
Reputation: 3135
I have not been able to identify what the real cause of the problem is. It seems to be changes made in the 4.5.2 version of the framework. I did find the following work around.
At the beginning of the application simply create a tool tip and display it. This seems to cause things to get constructed correctly. For example:
[STAThread]
static void Main()
{
ToolTip tt = new ToolTip();
tt.IsOpen = true;
tt.IsOpen = false;
...
}
I would still like to know what the real issue is, so if anyone knows please post.
Upvotes: 0