So I'm working on this application that was developed by other people that are not involved with the project anymore. As stated in the title there are a few thread.sleep() calls that have me scratching my head. I have no experience working with AD.
The worst offender is the following one with a 50 second sleep in a class that inherits
public class Computer:ComputerPrinciple
public void MoveToOu(string ou)
var userObject = (DirectoryEntry)GetUnderlyingObject();
var newParentOu = new DirectoryEntry("LDAP://" + ou);
computer.UpdateComputerOu(collection); <--- offending MoveToOu method is called in here
This use of
Thread.Sleep is likely a workaround for not calling
If UsePropertyCache is true, call the CommitChanges method on the new object to make the move permanent
It looks like they were waiting for the cache to flush using an empirical delay.
Second, wrapping any
IDisposable you create inside
using will not break anything. It is the correct way to go. Objects used, but not created, inside
MoveToOu scope should not be disposed here, but rather be left to the container class dispose mechanism.