1
votes

I have a Plugin in MS Dynamics CRM 2011 which gets called on any new fixture creation. I want a task to run asynchronously when this plugin is called.

This will create around 40000 new rows in a table and is a long query which takes about 10 minutes to complete. I don't want Admin/User to wait while it completes creating all the records, I would rather let it running asynchronously and let user do other stuff.

Any help or sample code would be appreciated.

3

3 Answers

2
votes

I would suggest taking this outside of CRM into a separate process, e.g. scheduled console application, which periodically queries CRM for a particular situation and then creates the required records.

As a side, if your plugin is registered inside the sandbox, if it runs for more than 2 minutes CRM will stop it.

Event Execution Pipeline

Regardless of whether a plug-in executes synchronously or asynchronously, there is a 2-minute time limit imposed on the execution of a plug-in registered in the sandbox. If the execution of your plug-in logic exceeds the time limit, a System.TimeoutException is thrown. If a plug-in needs more processing time than the 2-minute time limit, consider using a workflow or other background process to accomplish the intended task.

0
votes

I would suggest you to use Async Plugin to achieve your goal.

0
votes

I tried using plugin for this purpose and it did not work for several reasons and one of them was time out issue.

Finally I manage to make this work by using custom Workflow Activity which gets fired on insert into my entity.

This works perfect and runs async for (30-45min) depending on data.

Thanks for all suggestions