I'm using GetTokenInformation
with the TokenGroups
flags to retrieve all the groups that a particular token is part of. I'm then looping through each of the returned SIDs and using LookupAccountSid
to grab the user name and domain. I call LookupAccountSid
twice: the first time to grab the size of the name and domain character arrays and the second time populates the allocated StringBuilder
s.
I'm getting very long delays. I've run ANTS to see what the issue was and found that if a user was part of 23 groups this that the entire sequence would take 15 seconds! The profiler points to the first call of LookupAccountSid and states that it was averaging 652开发者_Go百科 ms per call.
This is what the call looks like:
LookupAccountSid(null, tokenGroups.Groups[i].SID, null, ref accountCount, null,
ref domainCount, out snu);
accountCount
and domainCount
are initialized to 0 prior to this call. In the end the call is working but this delay is way to long. What am I doing wrong?
It is impossible to accurately measure time taken when running a profiler.
It is only useful when compared to all the times of other methods.
Run the call using Stopwatch as a timer without debugging info/attaching a debugger, and optimizations turned on.
Edit:
I have code that runs about 100 times longer when a profiler is attached (10 seconds) vs NGEN'd app (0.1 seconds).
精彩评论