I'm looping through the 10,000 items & exporting data to the excel.
If I limit loop to the 2k OR 3k items then there is no issue. everything works fine & data will get exported. but when loop goes for 10k items then its throwing thread aborted exception after 5k items.
In loop, I'm loading 3 xml documents. Exceptions also throwing at System.Xml.XmlDocument.LoadXml(String xml).
Below is my code for your Reference:
XmlDocument siteAdminXmlDocument = new XmlDocument();
XmlDocument engagementXmlDocument = new XmlDocument();
XmlDocument requestXmlDocument = new XmlDocument();
foreach (var request in provisioningRequests)
{
//Load SiteAdmin XML
siteAdminXmlDocument.LoadXml("<engagementAdministrators xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"></engagementAdministrators>");
string siteAdminXmlData = request.SiteAdminsXml;
if (siteAdminXmlData != null)
{
siteAdminXmlDocument.LoadXml(siteAdminXmlData);
}
//Load Engagement XML
engagementXmlDocument.LoadXml("SyncXml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"></SyncXml>");
string engagementXmlData = request.EngagementXml;
if (engagementXmlData != null)
{
engagementXmlDocument.LoadXml(engagementXmlData);
}
//Load Request XML
requestXmlDocument.LoadXml("<engagementRequest xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"></engagementRequest>");
string requestXmlData = request.RequestXml;
if (requestXmlData != null)
{
requestXmlDocument.LoadXml(requestXmlData);
}
////Here I'm getting data from xml nodes & writing to the Response//////
}
Error:
Thread was being aborted.
at System.Threading.Monitor.Enter(Object obj)
at System.Xml.XmlElementListListener.OnListChanged(Object sender, XmlNodeChangedEventArgs args)
at System.Xml.XmlNodeChangedEventHandler.Invoke(Object sender, XmlNodeChangedEventArgs e)
at System.Xml.XmlElement.AppendChildForLoad(XmlNode newChild, XmlDocument doc)
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
NOTE: All 10,000 items are having same data. (i.e. those are 10k copies of single item in database table. i.e dummy data)
While googling I found some solutions on this but none of them are applicable in this case. Anyone knows why this happening? Any help will be appreciated.