I want to do this..
but my app spawns multiple threads that want to access the log and so can cause multi-access problems. So, I thought Synclock would be the way to go. However, as the sub is shared I can't synclock it where it is being called, yet can't Synclock oWrite within the sub as it would need to be instatiated before the synclock block, which would be enough to cause concurrent access errors.
I thought something like
would help, but no luck - still have concurrent access errors raised on the instatiation of oWrite.
Any ideas?
Code:
Public Shared Sub log(ByVal p_strMessage As String)
Dim oWrite As System.IO.StreamWriter = System.IO.File.AppendText(Location)
Dim strLogEntry As String
strLogEntry = DateTime.Now.ToString & ": " & p_strMessage & Environment.NewLine
oWrite.Write(strLogEntry)
oWrite.Flush()
oWrite.Dispose()
oWrite = Nothing
End Sub
I thought something like
Code:
Public Shared Sub log(ByVal p_strMessage As String)
Dim token As New Object
SyncLock token
Dim oWrite As System.IO.StreamWriter = System.IO.File.AppendText(Location)
Dim strLogEntry As String
strLogEntry = DateTime.Now.ToString & ": " & p_strMessage & Environment.NewLine
oWrite.Write(strLogEntry)
oWrite.Flush()
oWrite.Dispose()
oWrite = Nothing
End SyncLock
End Sub
would help, but no luck - still have concurrent access errors raised on the instatiation of oWrite.
Any ideas?