Solved

C# JumptList crash while refreshing the list

Posted on 2010-11-16
15
714 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
15 Comments
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I checked and it seems like it is running in the same thread (The thread IDs match).
0
 
LVL 35

Expert Comment

by:Miguel Oz
Comment Utility
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
Comment Utility
It's a desktop WPF application
0
 

Author Comment

by:xNejX
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 8

Assisted Solution

by:cubaman_24
cubaman_24 earned 200 total points
Comment Utility
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
Comment Utility
@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
Comment Utility
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 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Anyone?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now