CoverageInfoManager是否支持多线程?

时间:2013-09-30 08:06:31

标签: c# xml mstest code-coverage

目前我的项目正在使用CoverageInfoManager将MSTest代码覆盖率转换为xml。见下面的代码

  foreach(var coverageFile  in coverageFolder)
  {
       CoverageInfoManager.ExePath = "<executable_search_paths>";
       CoverageInfoManager.SymPath = "<symbol_search_paths>";
       CoverageInfo info = CoverageInfoManager.CreateInfoFromFile(coverageFile); 
       CoverageDS dataSet = info.BuildDataSet(null); 
       CoverageInfoManager.Shutdown();
 }

由于我想要处理多个覆盖文件,所以我想以多线程方式处理文件,在C#中可能是这样的:

       Parallel.ForEach(coverageFiles, coverageFile =>
       {
             CoverageInfoManager.ExePath = "<executable_search_paths>";
             CoverageInfoManager.SymPath = "<symbol_search_paths>";
             CoverageInfo info = CoverageInfoManager.CreateInfoFromFile("coverageFile "); 
             CoverageDS dataSet = info.BuildDataSet(null); 
             CoverageInfoManager.Shutdown();
       });        

通过运行此代码,

上有一个例外
 CoverageInfo info = CoverageInfoManager.CreateInfoFromFile("coverageFile "); 

异常消息:

Item has already been added. Key in dictionary: '2383aa6b-a3b9-434c-8fc0-ebca44056838'  Key being added: '2383aa6b-a3b9-434c-8fc0-ebca44056838'

有人知道代码是否可以在多线程方式下工作吗?还是有其他方法可以在需要处理大量覆盖文件时使其运行得更快?

谢谢你们!

0 个答案:

没有答案