I'm having problems with renaming a directory multiple times, it seems to lock the file.
// e comes from a objectListView item
DirectoryInfo di = (DirectoryInfo)e.RowObject;
DirectoryInfo parent = Directory.GetParent(di.FullName);
String newPath = Path.Combine(parent.FullName, e.NewValue.ToString());
// rename to some temp name, to help change lower and uppercast names
di.MoveTo(newPath + "__renameTemp__");
di.MoveTo(newPath);
// Trying to cleanup to prevent directory locking, doesn't work...
di = null;
parent = null;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
Any help is much appreciated, because the first rename works okay, but when trying to do a new rename on the renamed folder, it throws an exception :
The process cannot access the file because it is being used by another process. A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
So first time rename that folder works, second time throws exception, I'm guessing the application holds a lock on the new folder, but how to work around it? I should be able to rename a folder twice right?