The data for my application is being stored on AWS S3. When users make changes to any of the data files (and are connected to AWS), the save routines automatically upload the data fiels to AWS. This seems to be working fine.
The application also automatically downloads the data files if the local file is out of date by more than 2 seconds. This is done in a secondary thread.
The problem is, if I try to open the file while it is downloading, an error is thrown. I tried to trap for this using file attributes, but it doesn't seem to be working correctly. Here is the file open sub in my CDataFile utility class:
Public Function OpenNewFile() As Short
Dim tmpFileNum As Short = FreeFile()
Dim iFlName As String = FullFileName()
Dim t As Boolean = False
Dim ex As Exception = Nothing
For i As Byte = 0 To 15 Step 1
Dim t1 As Short = System.IO.File.GetAttributes(iFlName)
If Not (t1 = FileAttributes.Offline) Then
Try
FileOpen(tmpFileNum, iFlName, OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Shared, RecordLength)
t = True
Exit For
Catch ex
End Try
Else
Threading.Thread.Sleep(1000)
End If
Next i
If t = False Then
MsgBox(ex.ToString)
tmpFileNum = -1
End If
Return tmpFileNum
End Function
Is there is a better method to trap for a file that is being downloaded?
Does the file attribute "Offline" return the correct value if the file is being downloaded?