Category Archives: Plugins

Simulate long operations in Dynamics 365 (CRM)

This article describes how to simulate a long operation in Dynamics 365 (CRM) using a simple custom plugin that introduces a delay using the Thread.Sleep function.

Background: recently we have been investigating an issue regarding some timeouts happening in a third party application which connects to our Dynamics 365 service. At the moment, it is difficult to tell if those timeouts are due to some slow connections to Dynamics or other reasons. In order to help us with this investigation, we are going to set the Timeout property of the OrganizationServiceProxy in the client application, which by default is 2 minutes.

Before applying this change, we also want to test it and simulate some long queries that would last longer than the client timeout limit set for the OrganizationServiceProxy. Here is where we have created this simple plugin “DelayOperation” that is going to introduce a delay for a certain number of seconds.

ramontebar_blog_Delay Operation Plugin_Sequence Diagram

For testing purpose, I have prepared a simple test that creates a Task record. See below the corresponding code:

ramontebar_blog_Create Task Test - Set OrganizationServiceProxy Timeout

Then we have registered our “DelayOperation” plugin in the create message of the Task entity, see below this plugin registration step:

ramontebar_blog_DelayOperationPlugin_Assembly Registration

ramontebar_blog_Delay Operation Plugin_Step Registration

Notice we pass the number of milliseconds to be used by the Thread.Sleep function as an unsafe plugin parameterIn our example, the client would wait for 10 seconds and the plugin would delay the operation for 12 seconds, causing the client to timeout.

Finally, our “DelayOperation” plugin code is:

ramontebar_blog_DelayOperationPlugin

You can download all this code from the following Github project:

https://github.com/rtebar/Dynamics-Utils

 I hope you find it useful!