Hi,
I need to be able to write data to a file from different application.
For example, i have a system that runs on different server, this system is multithreaded.
When 1 Processor (win service) has a max of 10 processing threads, and there are 10 processors in the network, 100 (10x10) records will be processed at the same time.
i have tried different code samples, but i allways keep getting the error that the file is used by an other process.
How to solve the fileaccess problem?Code:'// Open FileStream Dim objStream As New IO.FileStream("Output\Products.txt", IO.FileMode.Append, IO.FileAccess.Write, IO.FileShare.Write) SyncLock objStream Dim varPos As Long = objStream.Position 'Get Stream WriteBuffer StartPos Dim varLen As Long = varBufferLine.Length 'Get Stream WriteBuffer Length objStream.SetLength(varPos + varLen) 'Preserve Buffer in File objStream.Lock(varPos, varLen) 'Lock Buffer in File objStream.Write(System.Text.Encoding.Default.GetBytes(varBufferLine), 0, varBufferLine.Length) 'Write Buffer objStream.Unlock(varPos, varLen) 'Unlock the File End SyncLock objStream.Flush() objStream.Close()




)
Reply With Quote