Lock file

M

macneed

Can i lock a file in c#,
that i can move it and del it,
but other program don't have right to access(read) until i release it?

i read fileshare.none, but can't delete it without close the filestream or
streamwriter
there was still a cocurrency problem if i close the stream and delete it
just after close
what can i do?
 
P

Pavel Minaev

Can i lock a file in c#,
that i can move it and del it,
but other program don't have right to access(read) until i release it?

i read fileshare.none, but can't delete it without close the filestream or
streamwriter
there was still a cocurrency problem if i close the stream and delete it
just after close
what can i do?

I don't see why you'd want to forbid other processes from deleting
your file while you're working with it. Deletion will not delete the
actual data for as long as the file remains open - so, if another
process requests to delete the file, it will become invisible, but
your program can finish doing whatever it was doing with it. When you
close your file handle, the file will be physically deleted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top