开发者

analyze how many threads in application and what are they doing?

I have some c# application which I have to modify. When I'm modifing some method I need to know if I should make it thread-safe.开发者_JAVA技巧 How can I check if the particular method could be called from different threads? Are there any static-analyzing utilities?

I've tried to run my application and discovered in Task Manager that it contains 5 threads. I've scanned sources and so far the application is supposed to be single-threaded. Why there are 5 threads? Probably .net contains some "service" threads? How can I check who created these 5 threads and what are they doing? Are there any runtime analyzing utilities?

Thanks


One thing you can do, you the debugger: goto Debug | Break All, setup one window to view threads, another nearby to view the call stack. Make sure you are using a Microsoft symbol server (makes it possible to view call stacks). Then click on each thread and view its call stack. See if any of the call stacks contain your app code. .NET does add some threads to your app, one of which is the Finalizer thread, I don't what the other are, off the top of my head.

Another option, stick a breakpoint in the particular method, whenever it gets hit, either look at the current thread in the threads window, or configure the breakpoint to printout the current thread ID instead of breaking, so you can later examine the output window text.

Obviously this isn't comprehensive, but it's a start.


The only viable way to do this is to understand the design of the system and you are not going to do that with any tool. You will only be able to do this by reading the code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜