我该怎么做才能让这个循环运行得更快?
private void accessVendorGridData()
{
try
{
foreach (var item in getAllVendorList)
{
item.CurrencyName = "USD";
// Fetch Addresses in Vendor Grid
var Addr = _vendorservice.GetAllVendorAdd().Where(x => x.vendorId == item.Id).ToList();
if (Addr.Count > 0)
{
item.VendorAddressLine = String.Format("{0}, {1}, {2}, {3}, {4}", Addr[0].Address, Addr[0].City, Addr[0].StateProvince, Addr[0].ZipPostalCode, Addr[0].CountryRegion);
}
// Fetch Payment terms in Vendor Grid
var paymentTerm = _vendorservice.GetAllPaymentTerms().Where(x => x.Id == item.PaymentTermId).ToList().SingleOrDefault();
if (paymentTerm != null)
{
item.paymenttermitem = paymentTerm.Name;
}
// Fetch Tax Scheme in Vendor Grid
var taxscheme = _vendorservice.GetAllTaxScheme().Where(x => x.Id == item.TaxschemeId).ToList().SingleOrDefault();
if (taxscheme != null)
{
item.TaxschemeName = taxscheme.TaxSchemaName;
}
}
}
catch (Exception ex)
{
_exLog.AddErrorLog(ex, "NewVendor, accessVendorGridData()");
ModernDialog.ShowMessage(ex.Message, "Error!", MessageBoxButton.OK);
}
}
我该怎么做才能让这个循环运行得更快?我尝试了 Parallel.ForEach 但在中间迷失了。有人可以帮忙吗?
jeck猫
相关分类