[C#] How do you check if a file is in use?
아래의 내용을 봤습니다.
https://stackoverflow.com/questions/876473/is-there-a-way-to-check-if-a-file-is-in-use
저는 아래 구문이 그런데로 나은듯한데요.
private bool IsFileLocked(string filePath)
{
try
{
using (Stream stream = new FileStream(filePath, FileMode.Open))
{
// File/Stream manipulating code here
}
}
catch (IOException ex)
{
return true;
}
finally
{
}
//file is not locked
return false;
}
잠시 생각해보니 궁금한 점이 생기네요.
IsFileLocked Method 에 접근하는 동안 Lock 이 발생하지 않을까요?
파일이 잠겨있는지 확인하는데 Lock 이 걸린다면.
stream 이 Close 될때까지의 시간이 그리 길지 않겠지만 말이죠.(당연히 파일의 크기에 따라 달라지겠죠?)
행복한 고수되셔요. ^^
woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\