Hello,
I have two services one I will call "Processor" the other we will call "Communicator". The Processor calls a function on the Communicator which tells it to contact a third party web service. The web service returns a file stream and the Communicator writes the stream to a DFS File System. Then the communicator returns the location of that file to the processor. The problem is that sometimes when the processor calls File.Exists(somefile) it returns false. However, the file is there!. I have tried using FileInfo and calling FileInfo.refresh but I get the same result. I have tried making the processor wait a few seconds which appears to work but that is not feasible as this service will see a lot of action during peak times. I am not sure if the DFS is taking too long to show the file as existing or if I am facing some sort of cache issue. Any and all suggestions are greatly appreciated.
some of my code is below
Communicator Saving Stream
Provider accessing file after return
Code I am using to make provider wait (it is ugly! )
I have two services one I will call "Processor" the other we will call "Communicator". The Processor calls a function on the Communicator which tells it to contact a third party web service. The web service returns a file stream and the Communicator writes the stream to a DFS File System. Then the communicator returns the location of that file to the processor. The problem is that sometimes when the processor calls File.Exists(somefile) it returns false. However, the file is there!. I have tried using FileInfo and calling FileInfo.refresh but I get the same result. I have tried making the processor wait a few seconds which appears to work but that is not feasible as this service will see a lot of action during peak times. I am not sure if the DFS is taking too long to show the file as existing or if I am facing some sort of cache issue. Any and all suggestions are greatly appreciated.
some of my code is below
Communicator Saving Stream
Code:
Public Sub CopyStreamToFile(ByVal input As Stream, ByVal filename As String)
If Not Directory.Exists(ProLibrary.ProPaths.ProPath.GetResponseSavePath()) Then
Directory.CreateDirectory(ProLibrary.ProPaths.ProPath.GetResponseSavePath())
End If
Using output As New System.IO.FileStream(Path.Combine(ProLibrary.ProPaths.ProPath.GetResponseSavePath(), filename), System.IO.FileMode.Create)
Dim data(CType(input.Length, Integer)) As Byte
input.Read(data, 0, CType(input.Length, Integer))
output.Write(data, 0, CType(input.Length, Integer))
output.Flush()
End Using
msRespSaveFile = Path.Combine(ProLibrary.ProPaths.ProPath.GetResponseSavePath(), filename)
End Sub
Provider accessing file after return
Code:
FileInfo fInfo = new FileInfo(zipfilename);
FileInfo fXMLInfo = null;
//WaitForFileExists(zipfilename);
fInfo.Refresh();
if (fInfo.Exists)
Code I am using to make provider wait (it is ugly! )
Code:
Public Sub WaitForFileExists(string zipfilename)
for (int i = 0; i < 20; i++)
if (!File.Exists(zipfilename))
ProLibrary.Utility.UtilityClass.ODS(String.Format("Loop Zip File Does Not Exist: {0:s}", zipfilename))
Thread.Sleep(250);
end if
next
end sub