tags:

views:

2130

answers:

4

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?

A: 

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?

Jeremy Wiebe
i didn't find any other running thread, whenever i break the application, i got this message "[In a sleep, wait, or join..."
Cooper.Wu
+1  A: 

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.

Davy8
how do i find "another thread" ?
Cooper.Wu
Debug -> Windows -> Threads, but I don't think it's availiable in the Express edition of VS if that's what you're using
Davy8
i saw "Threads" panel after i break the application, one main thread, and others threads, which were no named. all threads created in code i have named.
Cooper.Wu
+1  A: 

Hi Cooper

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.

Tor Haugen
Is that feature only available with the Team Foundation System?
daub815
+3  A: 

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

Cooper.Wu