线程a + b,(都试图删除文件)。 a首先被调用,然后在a仍在运行 时调用b 。b成功删除文件,但a没有。
如果我自己运行a,a的文件会被删除。
当我单步执行代码时,我可以看到a的 MultiAttemptFilename 被b覆盖。
我不明白。
我有一个指向通用处理程序的 ajax 调用,该处理程序将文件名连同它一起传递。在我的处理程序中,我有以下代码:
Dim Dc As New Document
Dim MyThread As New Thread(AddressOf Dc.DeleteFileMulitAttempt)
Dc.MulitAttemptFilename = Filename
MyThread.Start()
从我的“文档”类中,我调用以下内容:
#Region "Delete"
Public MulitAttemptFilename As String = ""
Public Sub DeleteFileMulitAttempt()
Dim TimeBetweenAttempts As Integer = 2000
Dim NumberOfAttempts As Integer = 60
Dim AttemptNumber As Integer = 0
Dim Success As Boolean = False
While (AttemptNumber < NumberOfAttempts)
Try
Success = (DeleteFile(MulitAttemptFilename) = "Ok")
Catch ex As Exception
Success = False
End Try
If (Success) Then Exit While
Thread.Sleep(TimeBetweenAttempts)
AttemptNumber += 1
End While
End If
End Sub
...
这是为了处理取消/失败的上传,因为它们并不总是立即删除(服务器锁定等),因此是循环。
我在这里错过了一些基本的东西吗?