From b4ae746d1c4af3c6a147a86717fb6d6f6101bfd4 Mon Sep 17 00:00:00 2001 From: Philipp Sumi Date: Sat, 16 Nov 2013 19:42:54 +0000 Subject: [PATCH] CHG If setting the taskbar doesn't work, the control just retries again (and again) rather than throwing an exception. git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@172 9f600761-6f11-4665-b6dc-0185e9171623 --- Source/NotifyIconWpf/TaskbarIcon.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/NotifyIconWpf/TaskbarIcon.cs b/Source/NotifyIconWpf/TaskbarIcon.cs index 78b5b8b..5b9df1a 100644 --- a/Source/NotifyIconWpf/TaskbarIcon.cs +++ b/Source/NotifyIconWpf/TaskbarIcon.cs @@ -26,7 +26,9 @@ using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; +using System.Runtime.Remoting.Channels; using System.Threading; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; @@ -878,7 +880,15 @@ namespace Hardcodet.Wpf.TaskbarNotification var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members); if (!status) { - throw new Win32Exception("Could not create icon data"); + //couldn't create the icon - we can assume this is because explorer is not running (yet!) + //-> try a bit later again rather than throwing an exception. Typically, if the windows + // shell is being loaded later, this method is being reinvoked from OnTaskbarCreated + Task.Factory.StartNew(() => + { + Thread.Sleep(1000); + CreateTaskbarIcon(); + }); + return; } //set to most recent version