SPRequestContext缓存SPSites引起的RPC_E_ATTEMPTED_MULTITHREAD错误解决方案? [英] solution for RPC_E_ATTEMPTED_MULTITHREAD error caused by SPRequestContext caching SPSites?

查看:28
本文介绍了SPRequestContext缓存SPSites引起的RPC_E_ATTEMPTED_MULTITHREAD错误解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 SharePoint 2007 开发解决方案,我经常使用 SPSecurity.RunWithElevatedPrivileges,传入 SystemAccount 的 UserToken.

I'm developing a solution for SharePoint 2007, and I'm using SPSecurity.RunWithElevatedPrivileges a lot, passing in UserToken of the SystemAccount.

阅读后http://hristopavlov.wordpress.com/2009/01/19/understanding-sharepoint-sprequest/ 我终于开始明白为什么我会得到这些 System.Runtime.InteropServices.COMException (0x80010102): Attempted to make calls on more than one thread in single线程模式.(来自 HRESULT 的异常:0x80010102 (RPC_E_ATTEMPTED_MULTITHREAD)) 错误,但似乎没有解决方案 - 产品中的已知问题"

After reading http://hristopavlov.wordpress.com/2009/01/19/understanding-sharepoint-sprequest/ I finally began to understand why I get these System.Runtime.InteropServices.COMException (0x80010102): Attempted to make calls on more than one thread in single threaded mode. (Exception from HRESULT: 0x80010102 (RPC_E_ATTEMPTED_MULTITHREAD)) errors, but there seems to be no solution - "known issue in the product"

这篇文章已经有一年多了.我找不到任何更新的有用的东西,但我希望也许其他人有?

The article is more then a year old. I wasn't able to find anything more recent and helpful, but I was hoping maybe someone else has?

我的代码是这样的

  SPSecurity.RunWithElevatedPrivileges(delegate()
  {
    using (SPSite elevatedSite = new SPSite(web.Site.ID, web.Site.SystemAccount.UserToken))
    {
      using (SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID))
      {
        // some operations on lists and items obtained through elevatedWeb
      }
    }
  }

在使用这种提升的代码的任何地方都会出现错误,并且当有更多的用户使用这些功能时,错误就会出现,所以我猜也许提升的 SPSite 正在被缓存和重用.

The errors come up wherever such an elevated code is used, and more often when there are more users who use these functionalities, so I guess perhaps the elevated SPSite is getting cached and reused.

有什么办法可以解决这个问题吗?如果我的理解是正确的,如何让 Sharepoint 忘记缓存的 SPSites,而是使用一个新的?

Is there any way to solve this? If my understanding is correct, how to make Sharepoint forget about the cached SPSites, and use a fresh one instead?

谢谢

推荐答案

我自己解决了这个问题,在最终理解了我在那里实际做了什么之后 - 通过使用例如 new SPSite(web.Site.ID,我实际上正在制作委托,似乎在一个新线程上,到达了原始线程上的网络

Solved it myself, after finally understanding what I'm actually doing there - by using for example new SPSite(web.Site.ID, I'm actually making the delegate, which seems to be on a new thread, reach into web, which is on the original thread

所以答案是:在运行委托之前,您已将需要的所有数据(如各种 ID、SystemAccount.UserToken 等)放入变量中,并且不要访问任何具有关联 SPRequest 的对象(网络、列表、项目、用户...)来自委托内部.当然,这同样适用于从委托中流出的数据 - 您可以返回 Web ID、列表 ID 和项目 ID,但最好不要返回 SPListItem.

So the answer is: you have put all the data you'll need (like various IDs, SystemAccount.UserToken etc.) into variables before running the delegate, and don't access any objects with associated SPRequest (webs, lists, items, users...) from inside the delegate. And, of course, the same holds for data that goes out of the delegate - you can return web ID, list ID and item ID, but you better not return SPListItem.

这篇关于SPRequestContext缓存SPSites引起的RPC_E_ATTEMPTED_MULTITHREAD错误解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆