From 748f4b0bd397cfbac6900b4b99646578b871ba5a Mon Sep 17 00:00:00 2001 From: Vikas Kumar Date: Mon, 25 Sep 2017 10:08:34 +0530 Subject: [PATCH 1/2] Possible fix for SFSDK-60 --- ShareFileSnapIn/SyncSfItem.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ShareFileSnapIn/SyncSfItem.cs b/ShareFileSnapIn/SyncSfItem.cs index 25bc51a..e17b7b8 100644 --- a/ShareFileSnapIn/SyncSfItem.cs +++ b/ShareFileSnapIn/SyncSfItem.cs @@ -820,8 +820,18 @@ private bool HasChildren(ShareFileClient client, Folder folder) /// private bool RemoveLocalItem(FileSystemInfo item) { - item.Delete(); - + try + { + item.Delete(); + } + catch (IOException ioe) + { + // File could not be deleted because it is locked. + // Calling Garbage collector explicitly to remove the object from the heap. + GC.Collect(); + GC.WaitForPendingFinalizers(); + item.Delete(); + } return true; } From d870e2df8143c0db8c775407f5822d098fb62d16 Mon Sep 17 00:00:00 2001 From: Vikas Kumar Date: Mon, 25 Sep 2017 10:21:23 +0530 Subject: [PATCH 2/2] Updating comments --- ShareFileSnapIn/SyncSfItem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ShareFileSnapIn/SyncSfItem.cs b/ShareFileSnapIn/SyncSfItem.cs index e17b7b8..b502582 100644 --- a/ShareFileSnapIn/SyncSfItem.cs +++ b/ShareFileSnapIn/SyncSfItem.cs @@ -826,8 +826,8 @@ private bool RemoveLocalItem(FileSystemInfo item) } catch (IOException ioe) { - // File could not be deleted because it is locked. - // Calling Garbage collector explicitly to remove the object from the heap. + // File could not be deleted because it is locked by an object present in heap. + // Calling Garbage collector explicitly to remove the object from the heap so as to unlock and delete the file. GC.Collect(); GC.WaitForPendingFinalizers(); item.Delete();