I have the following code in a console application:

for (int i=0;i<10000;i++) { fillValues();Write2SP()}

and in Write2SP(), I always do that:

ClientContext clientContext = new ClientContext(WebUrl);
List list = clientContext.Web.Lists.GetByTitle(Listname);
// and then search and either insert or update an item

Is there a way to stop reinitialize clientContext every time?somewhere in Main(); and using static variables?

Thank you

  • If it is always pointing to the same list or web, pass that in as a parameter to your Write2SP method so you don't have to constantly be initializing a new instance of the same object. – Eric Alexander Feb 24 '16 at 12:21
  • Before or after ExecuteQuery()? – XristosK Feb 24 '16 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.