web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Is the IOrganizationService.Execute method thread safe within a plugin?

(0) ShareShare
ReportReport
Posted on by

Currently working on a CRM 2016 onprem system but trying code for CRM Online whenever possible.

I would like to Execute several CRM Actions via the IOrganizationService.Execute method from within a CRM WFA using asynchronous Tasks so that my wait time is closer to that of the longest running action rather than the sum runtimes for all of the actions.

Does anyone know if the concrete implementation of IOrganizationService  returned from the plugin IOrganizationServiceFactory is thread safe? 

Alternately has anyone had success using the IOrganizationFactory to spin up multiple IOrganizationService objects within a plugin?

Thanks,

Scott Colson

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Michel van den Brink Profile Picture
    4,697 on at

    Hello,

    Yes it is thread safe. The IOrganizationService itself is just an interface but, the implementation you get from the OrganizationFactory is thread safe inside of the CRM context.

      

    Please keep in mind the following though:

    When CRM calls the Execute method on a your plugin or custom workflow activity (not the Execute method of the organization service) it will only create one instance of your IPlugin class or CodeActivity class

    You have to make sure your own Execute method is thread safe!

    On the same instance of your class CRM will try to call your Execute method multiple times, when needed.

      

    The IOrganizationFactory implementation will happily create new instances of the OrganizationService for you, which are thread safe.

      

    Hope this helps you. If you have any other questions, please let me know! :-)

  • Community Member Profile Picture
    on at

    Thank you Michel. I'll spin up additional org services and split the action executions across those.

    - Scott

  • Community Member Profile Picture
    on at

    Hello,

    this is not true, at least in a trial environment (I don't think production will be different) on version 1710 (9.1.0.1467) online.

    I have tried to create multiple instances of OrganizationService from a Custom Workflow Activity called by an Action, to use them for same parallel calls to the SaveChanges method (on new instances of OrganizationServiceContext), but the result is that they are serialized, this is the trace:

    ####2019-01-25 17:38:41.4601 534 DEBUG - SaveChanges 334ms

    ####2019-01-25 17:38:44.1248 522 DEBUG - SaveChanges 2973ms

    ####2019-01-25 17:38:47.4718 491 DEBUG - SaveChanges 6283ms

    ####2019-01-25 17:38:50.7237 507 DEBUG - SaveChanges 9535ms

    ####2019-01-25 17:38:53.9647 504 DEBUG - SaveChanges 12777ms

    ####2019-01-25 17:38:57.1886 523 DEBUG - SaveChanges 15999ms

    ####2019-01-25 17:39:00.5326 530 DEBUG - SaveChanges 19342ms

    ####2019-01-25 17:39:04.1396 512 DEBUG - SaveChanges 22953ms

    ####2019-01-25 17:39:07.2725 509 DEBUG - SaveChanges 26082ms

    ####2019-01-25 17:39:10.6275 513 DEBUG - SaveChanges 29439ms

    the same trace on my machine using OrganizationServiceProxy is this:

    ####2019-01-25 18:18:58.6289 17 DEBUG - SaveChanges 888ms

    ####2019-01-25 18:19:01.4624 21 DEBUG - SaveChanges 3677ms

    ####2019-01-25 18:19:01.4984 20 DEBUG - SaveChanges 3739ms

    ####2019-01-25 18:19:01.5054 18 DEBUG - SaveChanges 3760ms

    ####2019-01-25 18:19:01.5974 19 DEBUG - SaveChanges 3848ms

    ####2019-01-25 18:19:01.6224 16 DEBUG - SaveChanges 3818ms

    ####2019-01-25 18:19:01.8335 25 DEBUG - SaveChanges 4029ms

    ####2019-01-25 18:19:01.8896 24 DEBUG - SaveChanges 4103ms

    ####2019-01-25 18:19:01.9576 23 DEBUG - SaveChanges 4172ms

    ####2019-01-25 18:19:02.0897 22 DEBUG - SaveChanges 4304ms

    And if it gets overloaded this is the exception you get:

    Microsoft.Xrm.Sdk.SaveChangesException: An error occured while processing this request. ---> System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Concurrent calls to Sandbox SDK Listener are not allowed. Please work with plugin owner to make sure multiple SDK calls in parallel are not made to avoid this error.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans