开发者

Keep track of threads as they are spawned

Apologies in advance - I'm not the right person to be tackling this issue but there's a big snow storm today, and only the intern (me) was crazy enough to come in from my team.

Keeping it simple - I've got an application where after repeating a certain task (deserializing a file and making certain calls based on the data) about 115 times, there's a threshold where any of several other tasks will crash the application. All three of these actions that can crash the application involve showing new windows.

My best guess (garnered from staring at the Windows task manager thread count as I clicked repeatedly) is that we're not disposing of the threads correctly. The formula seems to be 4 threads spawned that hang around (more are actually created, most go away) each time I load a file. I want to know if theres a way I can step through the code and watch the number of threads as the process proceeds. Right now I really don't even know when or where threads are being started, but if I di开发者_如何学编程d I could follow their logic and make sure they aren't continuing to operate needlessly.

Thanks!


You can see all your application threads using IntelliTrace. Just pause it whenever you want, and you can see the call stack of each running thread.


I think the most likely thing is that you create the new forms or access forms/controls from a background thread.

To debug the issue, subscribe to the following events

AppDomain.UnhandledException and Application.ThreadException:

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

Put a breakpoint in each eventhandler and lock for the stack trace in the exception in the event args.


If you have access to the source of the method(s) that are being run in each thread, then you can insert some trace statements that append to a List, which you can view in the debugger or dump to a file to get an idea of the thread execution order. Lock around the List so to preserve the order of execution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜