C# System.Threading.Tasks.Task生成SPEException
在代码中使用System.Threading.Tasks.Task时,出现以下异常: SPException:尝试在单线程模式下对多个线程进行调用。(来自HRESULT的异常:0x80010102(RPC_E_尝试的_多线程))C# System.Threading.Tasks.Task生成SPEException,c#,multithreading,sharepoint,C#,Multithreading,Sharepoint,在代码中使用System.Threading.Tasks.Task时,出现以下异常: SPException:尝试在单线程模式下对多个线程进行调用。(来自HRESULT的异常:0x80010102(RPC_E_尝试的_多线程)) 请指出生成此异常的所有情况。每个上下文只能运行一个线程。如果需要对SharePoint对象执行多线程操作,可以使用以下截取部分作为参考: public static class SPListItemContextIsolatedExtension { publ
请指出生成此异常的所有情况。每个上下文只能运行一个线程。如果需要对SharePoint对象执行多线程操作,可以使用以下截取部分作为参考:
public static class SPListItemContextIsolatedExtension
{
public static SPListItem Isolate(SPListItem item)
{
var parentWeb = item.ParentList.ParentWeb.Url;
var site = new SPSite(parentWeb);
var web = site.OpenWeb();
return web.GetListItem($"{parentWeb}/{item.Url}");
}
public static void RunIsolated(this SPListItem item, Action<SPListItem> act)
{
Task.Factory.StartNew(() => act(item.Isolate()));
}
}
可能还有其他几种方法来实现隔离,上面的代码只是一个示例 也许或者可能帮助你。
item.RunIsolated(YourMethodHere);