bug(or my problem) in File.Open using FileShare.Write
-
Hi! I have an app that writes to a log file all the app's steps. I have several threads writing several times per second to the log file. The thing is that i have detected an exception with one of those writings, when i try to OPEN the log file. I use FileShare.Write so that there's no problem with writes form several threads at the same time(i thought).Did anybody experienced such a problem or is it my bug? I only write to the log in one function and i close the filestrems an the end.The code is: Try fs = File.Open(logPath & Format(Now(), "yyyyMMdd") & ".txt", FileMode.Append, FileAccess.Write, FileShare.Write) fsWriter = New StreamWriter(fs) fsWriter.WriteLine(Now & vbTab & entryString) Catch ex As Exception writeToErrorLog(ex.ToString) Finally If Not fsWriter Is Nothing Then fsWriter.Close() End If If Not fs Is Nothing Then fs.Close() End If End Try Never say never
-
Hi! I have an app that writes to a log file all the app's steps. I have several threads writing several times per second to the log file. The thing is that i have detected an exception with one of those writings, when i try to OPEN the log file. I use FileShare.Write so that there's no problem with writes form several threads at the same time(i thought).Did anybody experienced such a problem or is it my bug? I only write to the log in one function and i close the filestrems an the end.The code is: Try fs = File.Open(logPath & Format(Now(), "yyyyMMdd") & ".txt", FileMode.Append, FileAccess.Write, FileShare.Write) fsWriter = New StreamWriter(fs) fsWriter.WriteLine(Now & vbTab & entryString) Catch ex As Exception writeToErrorLog(ex.ToString) Finally If Not fsWriter Is Nothing Then fsWriter.Close() End If If Not fs Is Nothing Then fs.Close() End If End Try Never say never
You just told us "It's broke". What's the exception message? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
You just told us "It's broke". What's the exception message? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Ops...Sorry :P System.IO.IOException: The process cannot access the file "c:\myFile.txt" because it is being used by another process. Never say never