[SharePoint Developer Tip of the Day] Dealing with SPUpdatedConcurrencyException

2 views
Skip to first unread message

Dave Graham

unread,
Mar 4, 2009, 4:21:14 PM3/4/09
to sharepoint-develo...@googlegroups.com

SPUpdatedConcurrencyException is an exception thrown by the SPPersistedObject Update() method.  It indicates that another processes has updated the SPPersistedObject you have just modified and are trying to update.

I have found that best practice is to wrap all calls to Update on any SPPersistedObject to iterate until successful. Of course it is folly to iterate forever, so I have my code give up after 10 tires.  Here is a snip:

int count = 0;
while (true)
{
    try
    {
     MySPPersistedObject obj = FindMyObject(id);
     obj.SomeOperation();
     obj.Update();
     break;
    }
    catch (SPUpdatedConcurrencyException)
    {
     count++;
     if (count > 10)
     {
         throw;
     }
    }
}



--
Posted By Dave Graham to SharePoint Developer Tip of the Day at 3/04/2009 01:21:00 PM
Reply all
Reply to author
Forward
0 new messages