How do I set the user identity for tasks when calling Task.WaitAll()?

前端 未结 2 1955
南方客
南方客 2020-12-06 12:12

I\'m having a problem invoking WCF services in parallel. I\'m trying to use Tasks to invoke two services in parallel to save some time (I\'m NOT trying to make this async),

2条回答
  •  感情败类
    2020-12-06 13:05

    Try this:

    WindowsIdentity impersonatedUser = WindowsIdentity.GetCurrent();
    
    Task.Factory.StartNew(() =>
    {
        using (WindowsImpersonationContext ctx = impersonatedUser.Impersonate())
        {
           //Your code
        }
        return data;
    });
    
        

    提交回复
    热议问题