?
Solved

C# JumptList crash while refreshing the list

Posted on 2010-11-16
15
Medium Priority
?
728 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
15 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes

762 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