문제

I have an .exe and when I run it some files in one directory are being locked. I also have possibility in this .exe to rename that folder, and when I want to rename it of course I get the error that some files are being locked. Actually I have two questions: 1) What functionality causes files to lock? I mean could, for example, FileAccess enum affects to this? 2) How can I fix this problem?

도움이 되었습니까?

해결책

Whenever you open a stream (or a writer / reader, which wrap a stream), that locks the file.

You need to close your streams using the using statement.

다른 팁

1) What functionality causes files to lock?

This is caused because some process (potentially your program) has a file opened and locked, preventing other processes from manipulating it.

2) How can I fix this problem?

Make sure no process, including your own, keeps the files open when you try to perform the rename. This typically means making sure you always close your file streams, which can be handled automatically via the Using statement when you create or open your files.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top