I'm using SimpleImpersonation package, which does dirty work around some extern functions, for example
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);
I'm using it like this:
using (var imp = Impersonation.LogonUser(domain, user, password, LogonType.Interactive))
{
// another user
}
//me again
The problem is that this method impersonates user only for current thread, while I need to perform actions under another credentials from all threads in my application. How to achieve this?