1

目前我的项目正在使用 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'

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

感谢你们!

4

0 回答 0