J
John Talli
In the following function, it seems the file (p_s_FilePath_FileName) is NOT being
release. Can anyone tell me why the file is not being released? If I comment out the
program line that calls this function, the file can be processed in later processing. I
think I have tried everything I can including Threading.Thread.Sleep(2) [I was
desperate.] What am I doing wrong.
The error is :
The process cannot access the file 'C:\temp\Files.xml' because it is being used by
another process.
Thanks
=================
FUNCTION THAT IS NOT CLOSING THE FILE
=================
using System.Security.Cryptography;
public string GetMD5Checksum_From_File(string p_s_FilePath_FileName)
{
_bool_Is_Error = false;
StringBuilder sb = new StringBuilder();
try
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
FileStream fs = new FileStream(p_s_FilePath_FileName, FileMode.Open,
FileAccess.Read, FileShare.Read, 8192);
fs = new FileStream(p_s_FilePath_FileName, FileMode.Open, FileAccess.Read,
FileShare.Read, 8192);
md5.ComputeHash(fs);
fs.Close();
byte[] hash = md5.Hash;
//byte hByte = 0;
foreach (var h2Byte in hash)
{
sb.Append(string.Format("{0:X2}", h2Byte));
}
fs.Dispose();
fs = null;
md5 = null;
GC.Collect();
}
catch (Exception ex)
{
_s_Err_Msg = ex.Message.ToString().Trim(); << error msg stuff
sb.Append("".ToString()); << error msg stuff
_bool_Is_Error = true; << error msg stuff
}
return sb.ToString();
release. Can anyone tell me why the file is not being released? If I comment out the
program line that calls this function, the file can be processed in later processing. I
think I have tried everything I can including Threading.Thread.Sleep(2) [I was
desperate.] What am I doing wrong.
The error is :
The process cannot access the file 'C:\temp\Files.xml' because it is being used by
another process.
Thanks
=================
FUNCTION THAT IS NOT CLOSING THE FILE
=================
using System.Security.Cryptography;
public string GetMD5Checksum_From_File(string p_s_FilePath_FileName)
{
_bool_Is_Error = false;
StringBuilder sb = new StringBuilder();
try
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
FileStream fs = new FileStream(p_s_FilePath_FileName, FileMode.Open,
FileAccess.Read, FileShare.Read, 8192);
fs = new FileStream(p_s_FilePath_FileName, FileMode.Open, FileAccess.Read,
FileShare.Read, 8192);
md5.ComputeHash(fs);
fs.Close();
byte[] hash = md5.Hash;
//byte hByte = 0;
foreach (var h2Byte in hash)
{
sb.Append(string.Format("{0:X2}", h2Byte));
}
fs.Dispose();
fs = null;
md5 = null;
GC.Collect();
}
catch (Exception ex)
{
_s_Err_Msg = ex.Message.ToString().Trim(); << error msg stuff
sb.Append("".ToString()); << error msg stuff
_bool_Is_Error = true; << error msg stuff
}
return sb.ToString();