I am trying to debug a problem where users occasionally have locked files which they try to open. The code appears to have correct exception handling but users are still reporting seeing error messages. How can I simulate a locked file so that I can debug this myself?
EDIT: For Windows.
Right-click on the file. In the menu that appears, select Lock File. To unlock, right-click the file and select Unlock File.
As you said, notepad cannot lock it exclusively. Luckily, declaring a streamreader locks a file exclusively unless you specify otherwise.
try this:
( >&2 pause ) >> yourfile.txt
>>
opens yourfile.txt
in append mode
see this for a reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With