When I try to debug my code with debugger with F11 (Step Into), my code produced the expected result. When I try to run the code without debugger(without break point), the looping in my code produced unexpected result; to be specific, the looping part only loop for 1 times and terminated, I am confused here, anyone have any idea about this? Below is the loop I mentioned which produced unexpected result.
public bool CopyFileAndFolder(string sourceFolder, string replacePath)
{
bool result = false;
try
{
foreach (string extractPath in Directory.GetDirectories(sourceFolder, "*", SearchOption.AllDirectories))
{
string destFolder = extractPath.Replace(sourceFolder, replacePath);
if (!Directory.Exists(destFolder))
Directory.CreateDirectory(destFolder);
}
foreach (string extractFile in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))
{
string destFile = extractFile.Replace(sourceFolder, replacePath);
File.Copy(extractFile, destFile, true);
}
result = true;
}
catch (Exception)
{
result = false;
}
return result;
}
The complete code, i called the method above with this method:
private bool StartFileRollBackProcess()
{
bool result = false;
string backupFolder = Path.Combine(ConfigurationManager.AppSettings["BackupPath"], completeVersionNumber);
string destBackUpFolder = Directory.GetParent(iisConf.PhysicalPath).FullName;
try
{
DirectoryInfo folderToBeDelete = new DirectoryInfo(destBackUpFolder);
folderToBeDelete.Delete(true);
if (Directory.Exists(backupFolder))
{
Directory.CreateDirectory(destBackUpFolder);
result = CopyFileAndFolder(backupFolder, destBackUpFolder);
if (result)
{
ErrorMsg = "Copy process Failed,Your File has rolled back to previous version";
IsErrorDetected = true;
}
else
{
ErrorMsg = "copy got error";
IsErrorDetected = true;
}
}
}
catch (Exception)
{
ErrorMsg = "Error during roll up process";
IsErrorDetected = true;
}
return result;
}