文件更新期间的数据文件访问 [英] Data file access during file update

查看:63
本文介绍了文件更新期间的数据文件访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的数据存储在AWS S3上。当用户对任何数据文件进行更改(并连接到AWS)时,保存例程会自动将数据文件上传到AWS。这似乎工作正常。



如果本地文件已过期超过2秒,应用程序还会自动下载数据文件。这是在辅助线程中完成的。



问题是,如果我在下载文件时尝试打开文件,则会引发错误。我试图使用文件属性陷阱,但它似乎没有正常工作。这是我的CDataFile实用程序类中的文件open sub:



 ' 如果成功则返回文件编号,否则返回-1  
公共 功能 OpenNewFile()作为

' 打开数据文件
Dim tmpFileNum 作为 = FreeFile()
Dim iFlName As String = FullFileName()
Dim t As Boolean = 错误
Dim ex As Exception = Nothing

< span class =code-keyword>对于 i 作为 字节 = 0 15 步骤 1

Dim t1 As = System.IO.File.GetAttributes(iFlName)

如果 (t1 = FileAttributes.Offline)那么

尝试
FileOpen(tmpFileNum,iFlName,OpenMode.Random,OpenAccess.ReadWrite,OpenShare。 Shared ,RecordLength)
t = True
退出 对于

Catch ex

结束 尝试

否则
Threading.Thread.Sleep( 1000

结束 如果

下一步 i

如果 t = < span class =code-keyword> False 然后
MsgBox(ex.ToString)
tmpFileNum = -1
结束 如果

返回 tmpFileNum

结束 函数





是否有更好的方法来捕获正在存在的文件已下载?



如果正在下载文件,文件属性离线是否会返回正确的值?

解决方案

我建​​议您在AWS论坛上提出这个问题: https://forums.aws.amazon。 com / forum.jspa?forumID = 61 [ ^ ]

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:

' 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?

解决方案

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


这篇关于文件更新期间的数据文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆