0
내가 객체의 네 개의 컬렉션이 있습니다큰 개체 모음에서 새 개체 모음을 빠르게 만드는 방법은 무엇입니까?
public static ConcurrentBag<string> ProductCodes;
public static ConcurrentDictionary<string, Product> ProductDictionary;
public static ConcurrentBag<IIMIM00> iimiml; // 37782 items
public static ConcurrentBag<IIMAR00> iimarl; // 73516 items
public static ConcurrentBag<PRODUCTINF> additionall; // 6238 items
public static ConcurrentBag<PF_COSSTO> ProductsAndCosts; // 862096 items
나는에서 새로운 '제품'개체를 만들려면 제품 코드의 고유 목록을 얻을 모든 그래서 첫째 :
Parallel.ForEach(ProductsAndCosts, i => ProductCodes.Add(i.improd));
ProductCodes = new ConcurrentBag<string>(ProductCodes.Distinct().ToList())
제품 클래스 :
public class Product
{
public IIMIM00 iimim { get; set; }
public List<IIMAR00> iimar { get; set; }
public PRODUCTINF productAdditional { get; set; }
}
정렬하고 제품 코드 및 제품 객체 사전을 만들 수있는 나의 일상 :
를Parallel.ForEach(ProductCodes, SortandCreate);
public static void SortandCreate(string productCode)
{
var product = new Product {iimim = iimiml.Single(x => x.IMPROD.Equals(productCode))};
try
{
product.iimar = iimarl.Where(x => x.ARPROD.Equals(productCode)).ToList();
}
catch (Exception)
{
product.iimar = new List<IIMAR00>();
}
try
{
product.productAdditional = additionall.Single(x => x.PRODUCTCOD.Equals(productCode));
}
catch (Exception)
{
product.productAdditional = new PRODUCTINF();
}
ProductDictionary.TryAdd(productCode, product);
}
Product 개체가 항상 IIMAR00 또는 PRODUCTINF 인스턴스를 갖지 않으므로 try 캐치가 있습니다.
해결 방법은 매우 느립니다. i5에서 2:30 이상 걸립니다. 이 문제를 해결할 더 좋은 방법이 있는지 확실하지 않습니다.