【发布时间】:2015-09-20 07:22:49
【问题描述】:
我使用WindowsIdentity.Impersonate 来读取远程注册表。但是,读取位于Task 中的注册表的实际代码委托,因此它可能在不同的线程上运行。我的问题是在 UI 线程中模拟并在线程池中完成提升的工作是否合法?
更新:
// get userHandle from LogonUser(...)
Task task = Task.Run(() =>
{
using (impersonationContext = WindowsIdentity.Impersonate(userHandle))
{
// Do stuff here
if (impersonationContext != null)
{
impersonationContext.Undo();
}
}
}
【问题讨论】:
-
你说的合法是什么意思?
-
我的意思是即使它在我第一次尝试时有效,在某些情况下它也不会失败。试图了解模拟是应用于当前线程还是应用于所有线程/进程。
标签: c# winforms task-parallel-library impersonation