In this case, the account used by your code to List the directory may be different from the account which was used to create the directory.
Due to this, access privilege issue may occur eventually resulting in a timeout.
Please verify a single account is used for directory creation/Listing.
For example, Consider a Directory named '2012' and there are 2 sub-directories inside this namely 'JAN' and 'FEB'. Assume, 'JAN' was created programmatically and 'FEB' was created manually. Now, if you try to List 'FEB' directory from your program, the code may timeout due to which you feel like it is stuck.