1

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?

2 Answers 2

3

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.

5
  • your replies are always great at straight to the point, i spend almost 2 days trying to understand what is going on inside my ItemUpdated event receiver.so now inside my current ItemUpdated which runs async by default, i can retrieve the username whose action cause the event receiver to fire, is this correct ? Question2 also if i issue an update on the current item as follow SPListItem curItem = properties.ListItem; curItem["status"]="Open"; curItem.Update();
    – John John
    Jan 16, 2017 at 23:19
  • then the modifiedBy for the curItem will be equal to the user whose action caused the event receiver to fire and not equal to system account? is this correct ?
    – John John
    Jan 16, 2017 at 23:19
  • 1
    Yes, both are correct, but only if the event was ditectly fired by a user and not by a workflow or another receiver...
    – Cecilia
    Jan 17, 2017 at 5:41
  • So if the event receiver fires as part of a workflow activity then the user in this case will be the system account?
    – John John
    Jan 17, 2017 at 11:40
  • It depends on the workflow step type. In an "Impersionation Step" the user will be the system account or the user who created the workflow.
    – Cecilia
    Jan 17, 2017 at 17:26
1

John,

After events default to asynchronous mode.

See here: SPEventReceiverDefinition.Synchronization property

SharePoint event receivers: Making Asynchronous event Synchronous to avoid save conflict error

10
  • but seems in my case the event receiver is running in synchronous mode .. as it has the synchronous behavior for these reasons: - 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 (as in thr asynch event receivers),, for example if i try to add an item inside my "ItemUpdated" event receiver the modifiedby for the new item will be equal to the user who
    – John John
    Jan 15, 2017 at 2:40
  • trigger the event receiver and not equal to the system account... so my ItemUpdated event receiver is having all the properties for a synchronous event receiver is this correct ? or what do u think is happening in my event receiver!!
    – John John
    Jan 15, 2017 at 2:40
  • also inside the MSDN article it mentioned the following "If this property is set to Default for a Before event, this is equivalent to Synchronous. If this property is set to Default for an After event, this is equivalent to Asynchronous." but in my case i am not setting the value to "Default" as my element.xml is missing the whole <Synchronization> tag,..
    – John John
    Jan 15, 2017 at 2:47
  • can you advice on my above 3 comments please?
    – John John
    Jan 15, 2017 at 2:55
  • default is assumed if it's not set.
    – jpollar
    Jan 15, 2017 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.