Forcing closed an open file by C#

前端 未结 3 617
感情败类
感情败类 2021-01-04 03:44

I found a similar question here but it was closed/accepted with an answer of \"don\'t do that\".

I\'m in a situation where I don\'t care what happens to the other ap

3条回答
  •  爱一瞬间的悲伤
    2021-01-04 04:20

    This is probably irrelevant and if it is please someone comment but there was a work-around I've used in explorer before to get around file locks.
    If a file was locked by a process that had died Windows often wouldn't let you delete it but if you created a new file of the same name somewhere else, moved it to the folder it would succeed. You could then delete the new file and all was well.
    To use this for your app you'd have to be able to read the file and hold it in memory before you did this then you write it back out after you'd got rid of the old one.
    Maybe it will help, maybe not but it's worth trying.

提交回复
热议问题