?
Solved

C# JumptList crash while refreshing the list

Posted on 2010-11-16
15
Medium Priority
?
735 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:xNejX
  • 8
  • 3
12 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 1200 total points
ID: 34150399
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
 

Author Comment

by:xNejX
ID: 34150596
you are probably right, i think that it doesn't run in the main thread but how can i check?
0
 

Author Comment

by:xNejX
ID: 34150886
I checked and it seems like it is running in the same thread (The thread IDs match).
0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
LVL 36

Expert Comment

by:Miguel Oz
ID: 34152002
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
 

Author Comment

by:xNejX
ID: 34153510
It's a desktop WPF application
0
 

Author Comment

by:xNejX
ID: 34153532
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
 
LVL 8

Assisted Solution

by:cubaman_24
cubaman_24 earned 800 total points
ID: 34154809
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
 

Author Comment

by:xNejX
ID: 34155138
@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
 

Author Comment

by:xNejX
ID: 34156175
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
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 1200 total points
ID: 34159328
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
 

Author Comment

by:xNejX
ID: 34160707
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
 

Author Comment

by:xNejX
ID: 34196734
Anyone?
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Progress

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question