在一个共享点项目中,我有非常重要的事件接收器,到目前为止,已经为客户部署了该项目的 7 个版本。奇怪的是其中一个版本如此不稳定和缓慢。我的意思是有时在更新它的项目时会粘住。而这随机发生。
注意:他们的网络速度很好。问题肯定出在项目中。
我检查了代码并找到了处理错误的方式文件'FileName'已被SHAREPOINT\system修改导致循环,有时。这是要更新的代码ItemUpdated和ItemAdded事件接收器SPListItem:
base.EventFiringEnabled = false;
bool tryAgain = false; //used to handle "The file has been modified by SHAREPOINT\system"
do
{
    tryAgain = false;
    try
    {
        try
        {
            if (_item.File.CheckOutType == SPFile.SPCheckOutType.Online || _item.File.CheckOutType == SPFile.SPCheckOutType.Offline)
                 {
                     try
                     {
                          _item.File.CheckIn("prevent checkout/locked error");
                     }
                     catch (Exception ex) { }
                 }
           _item.SystemUpdate(true);
        }
        catch (Exception ex)
        {
             throw ex;  //-- used to handle "The file has been modified by SHAREPOINT\system"
        }
    }
    catch (Exception ex) //-- used to handle "The file has been modified by SHAREPOINT\system"
    {
        if (ex.Message.ToLower().Contains("has been modified by"))
        {
            System.Threading.Thread.Sleep(1000 * 2);
            tryAgain = true;
        }
        else
        {
            this.HandleException(ex, "");
        }
     }
} while (tryAgain == true);
此 while 循环具有以下状态:
1-item第一次更新,无一例外
2-更新原因提到了异常,它会在一段时间迭代后更新
3-更新原因提到了异常,它停留在一个循环中,即使在 200 次迭代后也不会更新。
这个问题导致项目不稳定,有时工作很慢。处理这种情况的最佳方法是什么?