【发布时间】:2010-08-14 00:05:50
【问题描述】:
我需要测试我经过严格测试的代码在被多个线程调用时是否有效
所以我使用 TreadPool.QueueUserWorkItem 在 TestMethod 中循环调用代码
但是,当所有启动的线程仍在运行时,似乎并没有保留当前线程。
即假装代码....
使用 Microsoft.VisualStudio.TestTools.UnitTesting
10 create a server
20 for( a number of iterations ) start a thread running a function
30 while all the threads are still doing stuff hang on to the server
40 now dispose of the server
无需等待,我的单元测试就会在工作完成之前处理服务器。
有什么值得感激的见解...?
【问题讨论】:
-
您是否正在为“服务器”对象寻找某种引用计数?
-
可以,谢谢建议
标签: .net multithreading unit-testing