Does my ItemUpdated event receiver execute Synchronous OR Asynchronous if i did not define a <Synchronization> inside the element.xml
-
13-12-2020 - |
Question
I have the following inside my sharepoint 2013 enterprise server:-
1- using Visual Studio professional 2012 i created a new ItemUpdated
Event receiver.
2- the event receiver will fire after a list item is updated.
3- the event receiver is scoped at the web level.
4- here is my Element.xml
file:-
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers>
<Receiver>
<Name>EventReceiver1ItemUpdated</Name>
<Type>ItemUpdated</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>CreateSubSiteforProjects.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
But i have noted that my element.xml
file is missing the <Synchronization>
tag,, and i have already deployed my event receiver.. so can anyone adivce if my ItemUpdate
event receiver is executing Synchronous OR Asynchronous? i mean what is the defualt behavior for the ItemUpdated
event receiver in sharepoint 2013 when the <Synchronization>
tag is not defined?
Now based on my test the ItemUpdated
event receiver , have the following Synchronous behavior (so not sure if i can be sure that my event receiver is running in Synchronous mode or not):-
1) i am able to get the user who trigger the event receiver using "properties.CurrentUserId;" and using "properties.Web.CurrentUser.LoginName.ToString()" .
2) also the current event receiver is running under the user permission and not under the system account permission.
so is my above event receiver running in Synchronous OR in Asynchronous mode?can anyone advice on this please?
Solution
Events ending by –ing are synchronous events (before): ItemAdding, ItemUpdating, ItemDeleting. Event handlers defined for these events are executed before the operation is executed on the content database. Asynchronous events are the events that end by –ed (after): ItemAdded, ItemUpdated, ItemDeleted. Event handlers for these events are executed after the operation is occurs in the content database.
After events runs asynchronously by default, after the page has already posted back and does not have a connection to the HttpContext of the firing page. If you want an after event to trigger synchronously, you have to specify it in the Element.xml file using the Synchronization property.
Even though the ItemUpdated
event runs asynchronously, it accepts the properties
parameter (an instance of SPItemEventProperties
class) that holds information about the item event, including fixed properties of the event such as event type, user name, and URL. This is why you can read the properties.CurrentUserId
and properties.Web.CurrentUser
properties.
OTHER TIPS
John,
After events default to asynchronous mode.
See here: SPEventReceiverDefinition.Synchronization property
SharePoint event receivers: Making Asynchronous event Synchronous to avoid save conflict error