Share via


Task is currently locked by a running workflow and cannot be edited

Workaround 1

CAUSE:
====================
Some objects like SPWeb,SPUser should be NonSerializable. In SPWorkflowTask.AlterTask, last parameter is for synchronization, we set to false

RESOLUTION/WORKAROUND:
====================
Make the alteration task not synchronous and make the NonSerialaized SP objects

If we use some objects like SPWeb,SPUser, it has to be NonSerializable. So we have to make those type of objects in the SharePoint workflow code as NonSerializable by adding the [NonSerialaized()] attribute on top of the declarations.

Eg:if you are using a SPWeb and SPUser as like this

private SPWeb oWeb = null;

private SPUser oUser = null;

then you can make those objects as NonSerialized like below,

[NonSerialized()]

private SPWeb oWeb = null;

[NonSerialized()]

private SPUser oUser = null;

Also, one more important change you have to make is synchronization = false while altering the task.

If we alter the task like this SPWorkflowTask.AlterTask(oTaskListItem, oTaskHash, true);, the third parameter represents a Boolean variable denotes synchronization is true or false. If we make it as true, it will make immediate modification on task (it mightcreate this locking issue) and if make it as false then it will depend on the timer activity and later it will be modified.

So if we get this error message, make the synchronization parameter as false. like below

SPWorkflowTask.AlterTask(oTaskListItem, oTaskHash, false);

Workaround 2

CAUSE
================
The above mentioned behavior is because of the “Task Locked” feature, when you try to alter a task (created through workflow), either through AlterTask() function or through Object Model. The reason behind is the workflow tasks are in queue for the timer schedule, as long as the task are queued, any attempt to alter the task would result in this error, which is by design. If a workflow is ‘waiting’ for an event from this task, it will be ‘locked’ and unchangeable until the workflow has had a change to process this event. Thus, we will have to wait for the timer schedule.

RESOLUTION
================
We have mentioned to them about the possible workarounds, which they need to test in your scenario. They are mentioned below:
Option 1: Add a Delay Activity
Option 2: Delegate all the Task updations to your OnTaskChanged Event.

Workaround 3

RESOLUTION
==========
To resolve the issue, need to change the taskId from fixed GUID to dynamic GUID.

Please implement these workarounds and let me know if it is working.

If we still have the problem, I would like to ask you to create a light version of our project and use it in another machine to reproduce the problem. Please send me this simple version so that I can work on my side.