Efficient use of PNP CSOM Core C#

Copper Contributor

I'm currently working through methods by which to make usage of PNP CSOM core more efficient on a large project that is expected to have loads of concurrent connections to and requests made of a SharePoint Online tenant.  As I understand it, the thing I want to cut down on the most is ExecuteQueryAsync calls followed by calls to create ClientContext.  

 

One thing I was looking into is creating ClientContext as a singleton, but in my research I've found that ClientContext isn't threadsafe, so that looks like it would eliminate that as an option.  Has anyone been able to successfully do this?

 

Here are some resources I've come across:

http://blog.repsaj.nl/index.php/2015/09/o365-parallel-processing-and-csom-friends-or-foes/

https://stackoverflow.com/questions/53893774/how-to-manage-client-context-object-in-seperate-class-l...

https://sharepoint.stackexchange.com/questions/96180/sharepoint-2013-csom-is-it-better-to-pass-a-con...

 

We have two main classes that handle SharePoint calls, and they currently have ClientContext created in several public methods.  My plan is to create one ClientContext per class vs several. 

 

I'm posting this to see what has worked for other folks,  what patterns have been used successfully and which have not etc.  

0 Replies