开发者

Knowing At what point the application freezes

开发者 https://www.devze.com 2022-12-20 20:51 出处:网络
I am developing a WinForm multithreaded application with C#. Sometimes it happens that my application hangs, or freezes or blocks.

I am developing a WinForm multithreaded application with C#. Sometimes it happens that my application hangs, or freezes or blocks.

When this happens and I am running in DEBUG mode, is there anyway to understand at what line of code my application is currently? Since it is freezed I expect to find a point where the application is locked or blocked or whatever. Is it possible to do that someway?

When I开发者_运维技巧t is freezed I tried to open the CALL STACK window, but this doesn't display any info; is there some action that I might do? Some "pause and check" or whatever?


You may need to open the Threads window, and change the current thread. While debugging, choose Debug->Break All, and open the Threads window. If you go through each thread, by double clicking on the thread, you should be able to investigate the call stack for each thread.

That being said, if you can run your program in VS 2010 - this gets a lot easier. In VS 2010, you can use the new Concurrency Profiler, and run your code under the Concurrency Profiler with the option to Visualize the Behavior of a multithreaded application. Once your application locks up, kill it, and let the profiler churn -

Eventually, you'll get a diagram which shows each thread in your program, and when they're locked. The callstack for each blocked thread will be shown, as well as what lock is being held (with the line of source code). This makes it very easy to track down a dead lock.


When debugger is attached go to Debug menu and choose 'Break All'... Then you can examine call stacks for all thread.


You could press pause and see where it ends up (use the aforementioned call stack window). Chances are however that you'll end up in native code. You could try to step out a bit or just look at the stack for a managed function to debug.

Alternatively you could put a breakpoint after the application "freezes" and try to pinpoint a loop that doesn't end.

Both the above are assuming your application is busy (100% cpu usage). If your application is however stuck in a dead lock or just plain waiting for a mutex that won't tick, you'll have to manually re-read your code and try to figure it out on your own.

0

精彩评论

暂无评论...
验证码 换一张
取 消