2016-06-29 1 views
-1

を生成し、私は以下の例外を取得しています:私のコードでSystem.Threading.Tasks.Taskを使用している間System.Threading.Tasks.TaskがSPException

SPException:内の複数のスレッド上で呼び出しを作成しようとしましたがシングルスレッドモード。 (HRESULTからの例外:0x80010102(RPC_E_ATTEMPTED_MULTITHREAD))

この例外が生成されるすべてのケースを指摘してください。

+0

多分[this](http://stackoverflow.com/a/3022813/5528593)または[this](https://social.msdn.microsoft.com/Forums/office/en-US/837f80b3-a497) -447b-b6cf-0cc6a60cba71/exception-rpceattemptedmultithread?forum = sharepointdevelopmentlegacy)が役に立ちます。 –

答えて

0

コンテキストごとに1つのスレッドしか実行できません。

item.RunIsolated(YourMethodHere); 

ありかもしれません:次に、あなたのような、拡張を呼び出すアクションを実行することができます

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())); 
    } 
} 

:あなたは、SharePointオブジェクトスレッドのマルチする必要がある場合は、以下の参考として切り取らを使用することができます上記のコードは単なる一例に過ぎません。

関連する問題