I have a thread which appends a 100 "_" into a file and another one a 100 "-" into the same file. Any idea how to synchronise them in order to get an output like _-_-_- etc.. I guess the solution will be similar in C#
C#:
Imports System.ThreadingImports System.IO
Module Module1
Dim NesneMutex As New Mutex
Dim fs As New FileStream("C:\\Data\\threadTesti.dat", FileMode.Append, FileAccess.Write)
Sub alt()
For i = 0 To 100
fs.WriteByte(Asc("_"))
Next
End Sub
Sub tire()
For i = 0 To 100
fs.WriteByte(Asc("-"))
Next
End Sub
Sub Main()
Dim t1 As New Thread(New ThreadStart(AddressOf alt))
Dim t2 As New Thread(New ThreadStart(AddressOf tire))
t1.Start()
t2.Start()
Console.ReadKey()
End Sub
End Module