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?

1
  • I used Performance Profiling for WPF tool to found out which events or element take high CPU usage, then we found: Tick(TimeManager.Tick()) was take about 40% CPU usage of app. which events will call TimeManager.Tick? how to reduce it? Commented May 12, 2009 at 6:44

4 Answers 4

5

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Debug -> Windows -> Threads, but I don't think it's availiable in the Express edition of VS if that's what you're using
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.
1

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.

1 Comment

Is that feature only available with the Team Foundation System?
0

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?

1 Comment

i didn't find any other running thread, whenever i break the application, i got this message "[In a sleep, wait, or join..."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.