Question

My WPF application used high CPU usage after about 30 minutes, then i break the application to find out what code spent high CPU usage, but i got nothing.

Visual Studio 2008 can't display current running code, but i found this in "Call Stack" panel:

[In a sleep, wait, or join] 
mscorlib.dll!System.Threading.WaitHandle.WaitAny(System.Threading.WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) + 0x8f bytes 
System.dll!System.Net.TimerThread.ThreadProc() + 0x2f9 bytes    
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x66 bytes   
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes    
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes   

what's this? what's matter with high CPU usage? and how to reduce the CPU usage?

Was it helpful?

Solution

We used "Performance Profiling Tool for WPF"/Visual Profile to found out which events take most CPU usage. Tick(TimeManager.Tick()) was take about 40% CPU usage of app. then we removed all Animation-Controls one by one, finally, we found there was a storyboard would increase CPU usage after about 30 mins.

then we changed form:


calendarStoryboard.Begin(txtMessage, HandoffBehavior.Compose, true);

to


calendarStoryboard.Begin(txtMessage, HandoffBehavior.SnapshotAndReplace, true);

this issue was fixed. the more information about HandoffBehavior please refer to msdn:

http://msdn.microsoft.com/en-us/library/system.windows.media.animation.handoffbehavior.aspx

OTHER TIPS

You should take a look at the other threads, I think the toggle to show threads is in the debug menu of visual studio. "[In a sleep, wait, or join" means that the thread can't do anything because it's waiting on another thread to complete it's operation.

It might be stuck in an infinite loop somewhere, either intentionally or not (intentionally such as some UI thing continuously redrawing, like an animation or something) Whatever it is, it's not in the current thread shown in your stack.

You have some options for tracking down your issue. I would start with the Performance Wizard in Visual Studio 2008. You'll find it on the Analyze menu.

I'm not a WPF expert, but the call stack you show here probably isn't your issue. That thread is waiting on some other synchronization object and isn't doing any work. The reason VS can't display the running code is because it's waiting in native code (once you call WaitAny() I believe you call into a native OS construct that does the actual waiting).

Are there any other threads running in your WPF process that may be using up CPU time?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top