Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
' return the file number if successful, else return -1
Public Function OpenNewFile() As Short

    ' Open the data file
    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?
Posted

1 solution

I suggest you to ask this question on AWS forum: https://forums.aws.amazon.com/forum.jspa?forumID=61[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900