I am sorry, I typed in incorrectly.
Pls tell me if the following is correct and thread safe.
Thanks.
Dim swError As TextWriter
Dim swErrorSync As TextWriter
swError = New StreamWriter(Application.StartupPath & "\Log.txt", True)
swErrorSync = swError.Synchronized(swError)
swErrorSync .Write(Now & vbCrLf)
swError.Close()
swErrorSync.Close()
"David Browne" <davidbaxterbrowne no potted
me**@hotmail.comwrote in
message news:u%****************@TK2MSFTNGP03.phx.gbl...
>
"fniles" <fn****@pfmail.comwrote in message
news:Ou**************@TK2MSFTNGP03.phx.gbl...
>Is this the correct syntax to make a Textwriter thread safe ? Thank you.
Dim swError As TextWriter
Dim swErrorSync As TextWriter
swError = New StreamWriter(Application.StartupPath & "\Log.txt", True)
swErrorSync = swError.Synchronized(swError)
swError.Write(Now & vbCrLf)
swError.Close()
No. Not quite. Threads should write to swErrorSync. And it's not clear
what code different threads are running. This snippet, as a whole, is
definitely not thread-safe.
David