Skip to content

Commit 085064d

Browse files
To support Impersonation
1 parent 116da3b commit 085064d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

SnaffCore/Concurrency/BlockingTaskScheduler.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Numerics;
4+
using System.Security.Principal;
45
using System.Threading;
56
using System.Threading.Tasks;
67

@@ -62,7 +63,13 @@ public void New(Action action)
6263
// okay, let's add the thing
6364
proceed = true;
6465

65-
_taskFactory.StartNew(action, _cancellationSource.Token);
66+
WindowsIdentity impersonatedUser = WindowsIdentity.GetCurrent();
67+
_taskFactory.StartNew(() => {
68+
using (WindowsImpersonationContext ctx = impersonatedUser.Impersonate())
69+
{
70+
action();
71+
}
72+
}, _cancellationSource.Token);
6673
}
6774
}
6875
}

0 commit comments

Comments
 (0)