C# JumptList crash while refreshing the list

Hi,

I'm using the new Windows 7 API in order to get the Jumplist in the taskbar to work. But i have a problem, when I call

jumpList.refresh() I get a Exception from HRESULT: 0x80040F07

ERROR DETAILS:

System.Runtime.InteropServices.COMException was unhandled
  Message=Exception from HRESULT: 0x80040F07
  Source=Microsoft.WindowsAPICodePack.Shell
  ErrorCode=-2147217657
  StackTrace:
       at Microsoft.WindowsAPICodePack.Taskbar.ICustomDestinationList.CommitList()
       at Microsoft.WindowsAPICodePack.Taskbar.JumpList.Refresh()
       at MyApp.SplashWindow.Genereate()
       at MyApp.SplashWindow.Window_Loaded(Object sender, RoutedEventArgs e)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
       at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
       at MS.Internal.LoadedOrUnloadedOperation.DoWork()
       at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
       at System.Windows.Interop.HwndTarget.OnResize()
       at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Window.ShowHelper(Object booleanBox)
       at System.Windows.Window.Show()
       at MyApp.App.OnStartup(StartupEventArgs e)
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at MyApp.App.Main()
  InnerException: 

Open in new window


SAMPLE C# CODE:

var jumpList = JumpList.CreateJumpList();
var systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System);
 
jumpList.AddUserTasks(new JumpListLink(Path.Combine(systemFolder, "taskmgr.exe"), "Open Task Manager")
{
      IconReference = new IconReference(Path.Combine(systemFolder, "taskmgr.exe"), 0)
});
 
jumpList.AddUserTasks(new JumpListLink(Path.Combine(systemFolder, "perfmon.exe"), "Open Resource Monitor")
{
      IconReference = new IconReference(Path.Combine(systemFolder, "perfmon.exe"), 0),
    Arguments = "/res"
});
 
jumpList.Refresh();

Open in new window


This happens only if I have jumpList.Refresh() in the code, if I dont it doesn't crash but the list doesn't populate.

This Only happens if I try to run / debug outside Visual Studio or inside VIsual Studio with the "Enable the Visual Studio hosting process" turned off. If I have the "Enable the Visual Studio hosting process" option ON it works.

It is an odd problem, I doubt that it has anything to do with the code as it is copied word for word from the official Microsoft Windows 7 API sample and it does work in other projects. So i guess that this is something in the project settings?

How can I solve this issue?
xNejXAsked:
Who is Participating?
 
Miguel OzSoftware EngineerCommented:
I have not done Win7 projects, but from your description I will say that you need to check if your code is executed in the main thread of your program.
the error shown aboce is tycial of code running on a thread different from main thread. Hosting process make it run as a separate exe thus your code becomes an exe in its own right, not just a thread part of VS
0
 
xNejXAuthor Commented:
you are probably right, i think that it doesn't run in the main thread but how can i check?
0
 
xNejXAuthor Commented:
I checked and it seems like it is running in the same thread (The thread IDs match).
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Miguel OzSoftware EngineerCommented:
What kind of application do you have? Desktop (winforms), web, etc.
Same threadId does not necesarily mean main thread, check:
http://stackoverflow.com/questions/2374451/how-to-tell-if-a-thread-is-the-main-thread-in-c
0
 
xNejXAuthor Commented:
It's a desktop WPF application
0
 
xNejXAuthor Commented:
I went through all of the methods on http://stackoverflow.com/questions/2374451/how-to-tell-if-a-thread-is-the-main-thread-in-c and all of them came back as the call is running in the main thread.

Any clues?
0
 
cubaman_24Commented:
Hello:
Check if you have the STAThreadAttribute applied to your main method.
http://msdn.microsoft.com/en-us/library/system.stathreadattribute.aspx
Best regards.

[STAThread]
        public static void Main(string[] args){
        //Your code
        }
}

Open in new window

0
 
xNejXAuthor Commented:
@cubaman_24

I dont have anything like that in my code. I tried to invoke it but that didn't help as I  got the same error.
0
 
xNejXAuthor Commented:
If it helps, I noticed something strange. When you normaly right click an icon of the running application you usualy see something like:

Test.exe
Pin this program to taskbar
Close window

But I can see only Close window when I right click it. Is the default JumpList even being created?

0
 
Miguel OzSoftware EngineerCommented:
WPF is an STA application but it is multithreaded by nature. Any rendering event is executed on a thread. Where is your code implemented? (i.e. button click, load event ..
0
 
xNejXAuthor Commented:
This code is implemented on the Window_Loaded event. I also tried to implement it on a button click or anything long after the Window is created, but the error was the same.
0
 
xNejXAuthor Commented:
Anyone?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.