So i have this function
that checks if my File
is still in use (in order to wait before try to copy and delete it):
private static bool IsFileLocked(FileInfo file)
{
FileStream stream = null;
try
{
using (stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
}
}
catch (IOException)
{
// The file is unavailable because it is:
// 1. Still being written to.
// 2. Being processed by another thread.
// 3. Does not exist (has already been processed).
if (stream != null)
stream.Close();
return true;
}
finally
{
if (stream != null)
stream.Close();
}
//file is not locked
return false;
}
So this is enough to call Close()
method or maybe use using
to ensure the file
Closed after finish my method ?