c# - Cannot access a file in multi-thread -


using (filestream fs = new filestream(path, filemode.append, fileaccess.write, fileshare.none)) {     using (streamwriter sw = new streamwriter(fs))     {         sw.writeline(datetime.now.tostring());              // multiple sw.writeline     } } 

in spite of fact fileshare set "none", exception launched "the process cannot access file because being used process.
i'm in multi-thread context , file not written/read somewhere else.

why ?

you trying write file multiple threads - not possible without sort of synchronization ensure file closed before attempting write thread.

as fileshare set none - means multiple threads not allowed share file, of course sharing violation exception.

none - declines sharing of current file. request open file (by process or process) fail until file closed.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -