파일을 FileStream
으로 제공 할 응용 프로그램을 빌드하고 있습니다. 파일 스트림이 클라이언트에 의해 일정 시간 동안 사용 상태로 남아있을 수 있기 때문에 소스 파일을 잠그지 않고이 작업을 수행 할 수 있어야하며 응용 프로그램은 소스 파일에 대한 후속 쓰기 작업을 수행해야 할 수도 있습니다.파일 복사본을 파일 스트림으로 반환하십시오.
기본적으로 소스 파일 자체가 아닌 파일 스트림으로 독립적 인 파일 복사본을 제공 할 방법을 찾고 있습니다. 파일이 클라이언트에 의해 잠겨 있기 때문에이 코드는 Await Task.Run(Sub() File.Copy(newSourceFilePath, serverFilePath, True))
에 IOException
가 발생합니다
Friend Sub Main(args As String())
Dim fs = GetServerFile()
Dim t = SomeOperationThatOverwritesServerFile()
'just simulate using the file for some period of time,
'even thought this probably isn't needed bc it's already locked anyway.
For i = 1 To 10
fs.Seek(0, SeekOrigin.Begin)
Threading.Thread.Sleep(1000)
Next
fs.Close()
End Sub
Friend Function GetServerFile() As FileStream
GetServerFile = File.OpenRead(serverFilePath)
End Function
Friend Async Function SomeOperationThatOverwritesServerFile() As Task
'just simulate something that overwrites the server file with fresh data.
For i = 1 To 5
Await Task.Run(Sub() File.Copy(newSourceFilePath, serverFilePath, True))
Await Task.Delay(2000)
Next
End Function
: 여기
내가 함께 시작한 POC이다. 공정하다. 지금 나는 그러나, 나는FileStream
생성자 오버로드 중 하나가 작동 확실하지 않다는
FileStream.CopyTo()
방법을 찾고 있어요 :
Friend Function GetServerFile() As FileStream
GetServerFile = File.OpenRead(serverFilePath).CopyTo(New FileStream(WHICH OVERLOAD DO I USE?))
End Function
그들은 모든 파일 또는 SafeFileHandle
에 String
경로를 거치게.
모든 안내를 주시면 감사하겠습니다.