Did you look at the code sample from ch 11 in the book samples that shows group membership expansion? You might try that instead.
One thing I saw with the sample you referenced is that it calls GetDirectoryEntry in a loop simply to read a single attribute. NEVER do this. You should never call GetDirectoryEntry from the SearchResult unless you need to modify. Always read attributes from the ResultPropertyValueCollection on the SearchResult. Calling GetDirectoryEntry causes 1 (or usually 2) additional searches to be submitted to the server for each call. In the example shown, it was being used to read a value that was already in memory. Not good.
There may be other approaches you want to try as well but start with the ch 11 sample and see if that gets you further.