开发者

LookupAccountSid taking +600 ms per call

开发者 https://www.devze.com 2023-01-14 04:53 出处:网络
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

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 StringBuilders.

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消