0

I have a code that loops continuously and during each iterations an item is added to SharePoint list CSOM. The code runs fine for some time and then I get an error

“The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ”

Any idea how to resolve this issue. The code snippet is given below
ClientContext context = <<get context refrence>>;

List announcementsList = context.Web.Lists.GetByTitle(“CSOM”);

for (int i = 0; i < 1000000; i++)
{
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem[“Title”] = DateTime.Now;
newItem.Update();
context.ExecuteQuery();
}

(Visited 635 times, 1 visits today)
Add a Comment