這是醜陋的,但它爲我工作
Function WaitForFile(fullPath, wdelay)
Dim vd_start As Date
vd_start = Now()
Dim vd_end As Date
Dim wsec, wmin, whour, wt5string As Integer
Dim wtstring As String
Dim count As Integer
Dim wscale As Integer
Dim vd_1 As Date
Dim Vo_fileinfo As FileInfo
Dim fs As FileStream
wsec = Format(wdelay Mod 60, "00")
wmin = Format(Int(wdelay/60), "00")
whour = Format(Int(wdelay/(60 * 60)), "00")
wtstring = CStr(whour) + ":" + CStr(wmin) + ":" + CStr(wsec)
Dim duration = New System.TimeSpan(0, whour, wmin, wsec)
vd_end = vd_start.Add(duration)
On Error GoTo error1
Dim vsize1, vsize2 As Long
While vd_start < vd_end
fs = New FileStream(fullPath, FileMode.Open)
fs.ReadByte()
fs.Seek(0, SeekOrigin.Begin)
fs.Close()
Vo_fileinfo = New FileInfo(fullPath)
vsize1 = Vo_fileinfo.Length
Threading.Thread.Sleep(500)
Vo_fileinfo = New FileInfo(fullPath)
vsize2 = Vo_fileinfo.Length
If vsize1 <> vsize2 Then GoTo error1
GoTo finalgoto
error1:
Err.Clear()
vd_start = Now()
End While
WaitForFile = False
GoTo Endgoto
finalgoto: WaitForFile = True
Endgoto:
End Function
來源
2014-07-22 15:46:00
Adz
我不」想如果文件需要一段時間才能複製這將工作。 – JohnFx 2009-01-12 23:23:07
副本是阻塞呼叫,他得到的問題是阻塞呼叫釋放和下一個代碼步驟之間的處理時間。這一點代碼只是幫助操作系統趕上。 – 2009-01-12 23:24:02
這聽起來有點腥。如果它阻塞,它應該在控制返回到調用模塊時完成操作。你是否認爲OS可能沒有足夠快地釋放文件上的鎖? – JohnFx 2009-01-12 23:27:03