amibar / SmartThreadPool

A .NET Thread Pool fully implemented in C# with many features
http://www.codeproject.com/Articles/7933/Smart-Thread-Pool
Microsoft Public License
507 stars 182 forks source link

Threads with context #2

Closed theouteredge closed 10 years ago

theouteredge commented 11 years ago

Hi,

I'm using the STP but wrapped within the following code:

using (new Impersonator( "myUsername", "myDomainname", "myPassword" ))
{
    [code that executes under the new context]
}

see code here: http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User?msg=4023519#xx4023519xx

But when the threads execute I get an error thrown stating: Invalid token for impersonation - it cannot be duplicated.

Do you know what is going on here? I've tried to set the UseCurrentContext but to no avail. Do you know how I can kick off a thread so it carried using the Impersonatoer context it was kick off within?

I'm assuming that I need to pass through the UserToken for the user I'm logged in as I but can't find how to do this anywhere

theouteredge commented 11 years ago

I've fixed this, nothing to do with STP. The WindowsIdentity was being disposed before the thread was executed causing the issue.