Welcome to Office 365 APIs | Microsoft Docs
Skip to main content

Office 365 APIs

This site contains the documentation for Office 365 REST APIs exposed on the OneNote and Outlook endpoints. The documentation is no longer actively updated. It is here for your reference, in case you have already included any of the API in your project.

Office 365 services, such as OneNote, Outlook, Excel, OneDrive, Microsoft Teams, Planner, and SharePoint, are now exposed in Microsoft Graph. Microsoft Graph is a unified API endpoint for accessing data across Microsoft 365, which includes Office 365, Enterprise Mobility, and Security and Windows services. It provides a simplified developer experience, with one endpoint and a single authentication token that gives your app access to data across all these services.

Our recommendation:

  • If you are starting a new app, please use Microsoft Graph.
  • If you are maintaining an existing project, use this documentation set for reference. In addition, plan your move to the latest APIs in Microsoft Graph to take advantage of all the new functionality and innovation there.
  • If you are adding new functionality to an existing project, integrate that new functionality by using Microsoft Graph.

With Microsoft Graph, you can access Office 365 data and more, from solutions across mobile, web, and desktop platforms. So whether you're building web applications by using .NET, PHP, Java, Python, or Ruby on Rails, or creating apps for the Universal Windows Platform (UWP), iOS, Android, or on another device platform, it's your choice.

In this section

 none
Event receiver running multiple threads RRS feed

  • Question

  • I created an ItemUpdated event receiver for a document library and I noticed while I was debugging that 2 threads are getting run. This is causing issues as I am copying/moving/deleting items in the doc library. I would have thought that the code would execute only once and not twice(once for each thread). I searched and didn't see anything about this.

    Just wondering if anyone could explain why the event receiver is running for more thread/multiple times.

    Thanks,

    Chris

    Monday, August 2, 2010 12:06 PM

Answers

  • hello

    this is not unusual situation when event receiver is called twice even you don't update properties of item inside this event receiver. For example here MS says that when you add file into doclib via WebDAV, ItemUpdating/ItemUpdated events are called twice and this is by design. When you work with doclib not via WebDAV - the same mechanisms may cause firing if event several times in different threads. Check this forum threads for more details: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/4252651d-243f-4031-a2e4-0dab81281a4a . If you need to ensure that your code is called one time - the only reliable way to do it is to use custom approach - e.g. add some timestamp field into your items and set it each time when your event receiver is called:

    try
    {
      this.DisableEventFiring();
      listItem["Timestamp"] = DateTime.Now;
      listItem.SystemUpdate(false);
    }
    finally
    {
      this.EnableEventFiring();
    }
    

    And before to execute the code check DateTime.Now and this timestamp: if difference is less then some wise default value (e.g. ~2 seconds), then you should treat such call as duplicated and do not perform any actions.

    Another mentioned issue (second call is executed in another thread) can be solved by adding of syncronization code into your receiver:

    public class CustomItemEventReceiver : SPItemEventReceiver
    {
      private static object lockObject = new object();
    
      public override void ItemUpdated(SPItemEventProperties properties)
      {
        lock(lockObject )
        {
          ...
        }
      }
    }
    


    Blog - http://sadomovalex.blogspot.com
    Codeplex - http://camlex.codeplex.com
    Monday, August 2, 2010 12:50 PM

All replies

  • Hi chris,

        I guess thats happening because you are trying to update another item of same list in ItemUpdated() method. To resolve this problem , do this:

    1) Add this.DisableEventFiring() before itemupdate statement and then add this.EnableEventFiring().

    this.DisableEventFiring();

    item.Update();

    this.EnableEventFiring().

    Regards,


    Manvir
    Monday, August 2, 2010 12:25 PM
  • hello

    this is not unusual situation when event receiver is called twice even you don't update properties of item inside this event receiver. For example here MS says that when you add file into doclib via WebDAV, ItemUpdating/ItemUpdated events are called twice and this is by design. When you work with doclib not via WebDAV - the same mechanisms may cause firing if event several times in different threads. Check this forum threads for more details: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/4252651d-243f-4031-a2e4-0dab81281a4a . If you need to ensure that your code is called one time - the only reliable way to do it is to use custom approach - e.g. add some timestamp field into your items and set it each time when your event receiver is called:

    try
    {
      this.DisableEventFiring();
      listItem["Timestamp"] = DateTime.Now;
      listItem.SystemUpdate(false);
    }
    finally
    {
      this.EnableEventFiring();
    }
    

    And before to execute the code check DateTime.Now and this timestamp: if difference is less then some wise default value (e.g. ~2 seconds), then you should treat such call as duplicated and do not perform any actions.

    Another mentioned issue (second call is executed in another thread) can be solved by adding of syncronization code into your receiver:

    public class CustomItemEventReceiver : SPItemEventReceiver
    {
      private static object lockObject = new object();
    
      public override void ItemUpdated(SPItemEventProperties properties)
      {
        lock(lockObject )
        {
          ...
        }
      }
    }
    


    Blog - http://sadomovalex.blogspot.com
    Codeplex - http://camlex.codeplex.com
    Monday, August 2, 2010 12:50 PM
Welcome to Office 365 APIs | Microsoft Docs
Skip to main content

Office 365 APIs

This site contains the documentation for Office 365 REST APIs exposed on the OneNote and Outlook endpoints. The documentation is no longer actively updated. It is here for your reference, in case you have already included any of the API in your project.

Office 365 services, such as OneNote, Outlook, Excel, OneDrive, Microsoft Teams, Planner, and SharePoint, are now exposed in Microsoft Graph. Microsoft Graph is a unified API endpoint for accessing data across Microsoft 365, which includes Office 365, Enterprise Mobility, and Security and Windows services. It provides a simplified developer experience, with one endpoint and a single authentication token that gives your app access to data across all these services.

Our recommendation:

  • If you are starting a new app, please use Microsoft Graph.
  • If you are maintaining an existing project, use this documentation set for reference. In addition, plan your move to the latest APIs in Microsoft Graph to take advantage of all the new functionality and innovation there.
  • If you are adding new functionality to an existing project, integrate that new functionality by using Microsoft Graph.

With Microsoft Graph, you can access Office 365 data and more, from solutions across mobile, web, and desktop platforms. So whether you're building web applications by using .NET, PHP, Java, Python, or Ruby on Rails, or creating apps for the Universal Windows Platform (UWP), iOS, Android, or on another device platform, it's your choice.

In this section