我在这里问这个是希望得到开发人员的回复......因为我搜索了网页而无法找到任何内容。
我目前在Visual Studio 2013中有一个Windows服务。项目运行正常,我可以毫无问题地使用VS.当我打开一个特定文件时,文本编辑器变得非常慢,智能感,自动完成只有一个.cs文件才会非常慢。切换回任何其他.cs文件,然后文本编辑器按预期工作。
为什么文本编辑器只使用这个文件会变慢,我该如何解决?只有大约1000行代码,而.cs文件中最复杂的是并行foreach循环
可能解析文件需要很长时间?!
编辑:
似乎Parallel.ForEach导致编辑器的速度变慢。如果我用正常的foreach替换Parallel.ForEach,那么我没有问题。
为什么会发生这种情况,我该如何解决?
//Get all required nodes
IEnumerable<XElement> childElements = from el in StreamRootChildDoc(fi.FullName, "PortfolioValuationsBranch") select el;
XNamespace ns = "http://www.namespacename.co.za/namespace";
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = 1; //Max Parallel inserts
Parallel.ForEach(childElements, options, element =>
{
string BranchCode = element.Element(ns + "Branch").Element(ns + "BrnCde").Value;
string BranchName = element.Element(ns + "Branch").Element(ns + "Name").Value;
string BranchAfrName = element.Element(ns + "Branch").Element(ns + "AfrName").Value;
IEnumerable<XElement> Partners = StreamRootChildDocString(element.ToString(), "PortfolioValuationsPartner");
foreach(XElement pElement in Partners)
{
//Parallel.ForEach(Partners, options, pElement =>
//{
string PartnerCode = pElement.Element(ns + "Partner").Element(ns + "ParCde").Value;
string PartnerName = pElement.Element(ns + "Partner").Element(ns + "Name").Value;
IEnumerable<XElement> Advisors = StreamRootChildDocString(pElement.ToString(), "PortfolioValuationsAdvisor");
foreach(XElement aElement in Advisors)
{
//Parallel.ForEach(Advisors, options, aElement =>
//{
string AdvisorCode = aElement.Element(ns + "Advisor").Element(ns + "AdvrCde").Value;
string AdvisorName = aElement.Element(ns + "Advisor").Element(ns + "Name").Value;
IEnumerable<XElement> Clients = StreamRootChildDocString(aElement.ToString(), "PortfolioValuationsClient");
foreach(XElement cElement in Clients)
{
//Parallel.ForEach(Clients, options, cElement =>
//{
IEnumerable<XElement> ClientNode = StreamRootChildDocString(cElement.ToString(), "Client");
string sID = (string)BuildClientID(BrokerCode);
string ClientCode = ClientNode.Select(x => (String)x.Element(ns + "ClntCde")).First();
PVClientTbl ClientData = ClientNode.Select(x => new PVClientTbl
{
ID = sID,
BrokerCode = BrokerCode,
StatementDate = FileMonthEndDate,
BrokerName = BrokerName,
BranchCode = BranchCode,
PartnerCode = PartnerCode,
AdvisorCode = AdvisorCode,
ClientCode = (String)x.Element(ns + "ClntCde"),
Title = (String)x.Element(ns + "Title"),
Initials = (String)x.Element(ns + "Initials"),
Surname = (String)x.Element(ns + "Surname"),
IDNumber = null,
ManagementCode = (String)x.Element(ns + "ManCde"),
Address1 = (String)x.Element(ns + "Address").Element(ns + "Addr1"),
Address2 = (String)x.Element(ns + "Address").Element(ns + "Addr2"),
Address3 = (String)x.Element(ns + "Address").Element(ns + "Addr3"),
Address4 = (String)x.Element(ns + "Address").Element(ns + "Addr4"),
PostalCode = (String)x.Element(ns + "Address").Element(ns + "PostCde"),
NonRes = null,
Facsimile = null,
Email = (String)x.Element(ns + "Emailadr"),
ElectronicIndicator = (String)x.Element(ns + "ElecInd"),
Language = (String)x.Element(ns + "Lang"),
TelNo1 = (String)x.Element(ns + "TelNo1"),
}).First();
bool bDidInsert = DAL.DigiLoaderDAL.CreatePortfolioClient(ClientData);
if (bDidInsert)
{
IEnumerable<XElement> HoldingTypeNode = StreamRootChildDocString(cElement.ToString(), "HoldingType");
foreach (XElement htElement in HoldingTypeNode)
{
string HoldingTypeDescription = (String)htElement.Element(ns + "Desc");
IEnumerable<XElement> HoldingSectorNode = StreamRootChildDocString(cElement.ToString(), "HoldingSector");
foreach (XElement hsElement in HoldingSectorNode)
{
string HoldingSectorDescription = (String)hsElement.Element(ns + "Desc");
List<HoldingsTbl> HoldingLineData = htElement.Descendants(ns + "HoldingLine").Select(x => new HoldingsTbl
{
ID = sID,
PVDate = null,
Type = HoldingTypeDescription,
Sector = "",
InstrumentAlpha = (String)x.Element(ns + "Instrmnt").Element(ns + "InstrAlpha"),
InstrumentName = (String)x.Element(ns + "Instrmnt").Element(ns + "Name"),
PriceFormat = (String)x.Element(ns + "PrceFormat"),
Movement = (String)x.Element(ns + "MoveQty"),
QuantityHeld = (String)x.Element(ns + "QtyHeld"),
CostEach = (String)x.Element(ns + "CostEach"),
CostTotal = (String)x.Element(ns + "CostTotal"),
CurrentEach = (String)x.Element(ns + "CurrEach"),
CurrentTotal = (String)x.Element(ns + "CurrTotal"),
Percentage = (String)x.Element(ns + "PFVPerc"),
DividendEach = (String)x.Element(ns + "DividendEach"),
DividendTotal = (String)x.Element(ns + "DividendTotal"),
YieldPercentage = (String)x.Element(ns + "YieldPerc"),
EarningsPerShare = (String)x.Element(ns + "EarningsPerShare"),
ApprDepr = (String)x.Element(ns + "ApprDeprAmt"),
GiltsAmount = (String)x.Element(ns + "GiltsAmt"),
CleanPriceEach = (String)x.Element(ns + "CleanPrceEach"),
AccuredInterest = (String)x.Element(ns + "AccruedInterest"),
Seq = x.ElementsBeforeSelf().Count() + 1,
}).ToList();
DAL.DigiLoaderDAL.CreatePVHoldings(HoldingLineData);
List<HoldingSectorAnalysisTbl> HoldingSectorAnalysisData = htElement.Descendants(ns + "HoldingSectorAnalysis").Select(x => new HoldingSectorAnalysisTbl
{
ID = sID,
Type = HoldingSectorDescription,
Sector = "",
CostTotal = (String)x.Element(ns + "CostTotal"),
CurrentTotal = (String)x.Element(ns + "CurrTotal"),
Percentage = (String)x.Element(ns + "PFVPerc"),
DividendTotal = (String)x.Element(ns + "DividendTotal"),
YieldPercentage = (String)x.Element(ns + "YieldPerc"),
ApprDepr = (String)x.Element(ns + "ApprDeprAmt"),
Seq = x.ElementsBeforeSelf().Count() + 1,
}).ToList();
//write to SQL
DAL.DigiLoaderDAL.CreatePVHoldingSectorAnalysis(HoldingSectorAnalysisData);
}
//HoldingTypeAnalysis
List<HoldingTypeAnalysisTbl> HoldingTypeAnalysisData = htElement.Descendants(ns + "HoldingTypeAnalysis").Select(x => new HoldingTypeAnalysisTbl
{
ID = sID,
CostTotal = (String)x.Element(ns + "CostTotal"),
CurrentTotal = (String)x.Element(ns + "CurrTotal"),
Percentage = (String)x.Element(ns + "PFVPerc"),
DividendTotal = (String)x.Element(ns + "DividendTotal"),
YieldPercentage = (String)x.Element(ns + "YieldPerc"),
ApprDepr = (String)x.Element(ns + "ApprDeprAmt"),
Seq = x.ElementsBeforeSelf().Count() + 1,
}).ToList();
//write to SQL
DAL.DigiLoaderDAL.CreatePVHoldingTypeAnalysis(HoldingTypeAnalysisData);
}
//cash detail
List<CashDetailTbl> CashDetailData = cElement.Descendants(ns + "CashDetail").Select(x => new CashDetailTbl
{
ID = sID,
Description = (String)x.Element(ns + "Desc"),
Amount = (String)x.Element(ns + "Amt"),
Percentage = (String)x.Element(ns + "CashPerc"),
Seq = x.ElementsBeforeSelf(ns + "CashDetail").Count() + 1,
}).ToList();
DAL.DigiLoaderDAL.CreatePVCashDetail(CashDetailData);
List<AnalysisTbl> AnalysisData = cElement.Descendants(ns + "PFVAnalysis").Select(x => new AnalysisTbl
{
ID = sID,
CostTotal = (String)x.Element(ns + "CostTotal"),
CostTotalInclCash = (String)x.Element(ns + "CostTotalInclCash"),
CurrTotal = (String)x.Element(ns + "CurrTotal"),
CurrTotalInclCash = (String)x.Element(ns + "CurrTotalInclCash"),
CashAmount = (String)x.Element(ns + "CashAmt"),
Percentage = (String)x.Element(ns + "PFVPerc"),
DividendTotal = (String)x.Element(ns + "DividendTotal"),
YieldPercentage = (String)x.Element(ns + "YieldPerc"),
ApprDepr = (String)x.Element(ns + "ApprDeprAmt")
}).ToList();
//sql insert
List<ProfitLossTbl> ProfitLossData = cElement.Descendants(ns + "ProfitLoss").Select(x => new ProfitLossTbl
{
ID = sID,
Description = (String)x.Element(ns + "Desc"),
Amount = (String)x.Element(ns + "Amt"),
}).ToList();
//sql insert
List<HistoricTbl> HistoricData = cElement.Descendants(ns + "HistoricalComparison").Select(x => new HistoricTbl
{
ID = sID,
Date = (String)x.Element(ns + "Date"),
CostTotal = (String)x.Element(ns + "CostTotal"),
CostTotalInclCash = (String)x.Element(ns + "CostTotalInclCash"),
CurrTotal = (String)x.Element(ns + "CurrTotal"),
CurrTotalInclCash = (String)x.Element(ns + "CurrTotalInclCash"),
CashAmount = (String)x.Element(ns + "CashAmt"),
DividendTotal = (String)x.Element(ns + "DividendTotal"),
YieldPercentage = (String)x.Element(ns + "YieldPerc"),
ApprDepr = (String)x.Element(ns + "ApprDeprAmt"),
}).ToList();
//sql insert
List<AssetAllocationTbl> AssetAllocationData = cElement.Descendants(ns + "AssetAllocation").Select(x => new AssetAllocationTbl
{
ID = sID,
Description = (String)x.Element(ns + "Desc"),
Amount = (String)x.Element(ns + "Amt"),
Percentage = (String)x.Element(ns + "PFVPerc")
}).ToList();
//sql insert
List<PVCopiesTbl> PvCopiesData = cElement.Descendants(ns + "AssetAllocation").Select(x => new PVCopiesTbl
{
ID = sID,
BrokerCode = BrokerCode,
StatementDate = FileMonthEndDate,
BranchCode = BranchCode,
PartnerCode = PartnerCode,
AdvisorCode = AdvisorCode,
ClientCode = (String)x.Element(ns + "ClntCde"),
Title = (String)x.Element(ns + "Title"),
Initials = (String)x.Element(ns + "Initials"),
Surname = (String)x.Element(ns + "Surname"),
IDNumber = null,
ManagementCode = (String)x.Element(ns + "ManCde"),
Address1 = (String)x.Element(ns + "Address").Element(ns + "Addr1"),
Address2 = (String)x.Element(ns + "Address").Element(ns + "Addr2"),
Address3 = (String)x.Element(ns + "Address").Element(ns + "Addr3"),
Address4 = (String)x.Element(ns + "Address").Element(ns + "Addr4"),
PostalCode = (String)x.Element(ns + "Address").Element(ns + "PostCde"),
NonRes = null,
Facsimile = null,
Email = (String)x.Element(ns + "Emailadr"),
ElectronicIndicator = (String)x.Element(ns + "ElecInd"),
Language = (String)x.Element(ns + "Lang"),
TelNo1 = (String)x.Element(ns + "TelNo1"),
NumberOfCopies = (String)x.Element(ns + "NumberOfCopies")
}).ToList();
//sql insert
//DAL.DigiLoaderDAL.CreateRec
}
else
{
Console.WriteLine("Error: did not insert client row");
}
}//);
}//);
}//);
});