Avatar of xNejX
xNejXFlag for Canada

asked on 

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?
.NET ProgrammingProgrammingMicrosoft DevelopmentC#

Avatar of undefined
Last Comment
xNejX
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of xNejX
xNejX
Flag of Canada image

ASKER

you are probably right, i think that it doesn't run in the main thread but how can i check?
Avatar of xNejX
xNejX
Flag of Canada image

ASKER

I checked and it seems like it is running in the same thread (The thread IDs match).
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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
Avatar of xNejX
xNejX
Flag of Canada image

ASKER

It's a desktop WPF application
Avatar of xNejX
xNejX
Flag of Canada image

ASKER

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?
SOLUTION
Avatar of cubaman_24
cubaman_24
Flag of Spain image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of xNejX
xNejX
Flag of Canada image

ASKER

@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.
Avatar of xNejX
xNejX
Flag of Canada image

ASKER

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?

SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of xNejX
xNejX
Flag of Canada image

ASKER

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.
Avatar of xNejX
xNejX
Flag of Canada image

ASKER

Anyone?
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo