当函数调用服务器时,文件将上载并存储在文件夹中。然后必须处理该文件,这需要一些时间,并会导致客户端超时。
为了解决这个问题,我想通过将文件的处理放在一个单独的线程中,以允许子程序在文件上传后返回到客户端。并且文件的处理将在后台继续。
不幸的是,线程正在停止返回。我不明白我遇到了什么问题。我认为通过使用线程,它将允许子例程完成并返回到客户端。
Public Sub RestoreToOps(rFileInfo As RemoteFileInfo) Implements IRestore.RestoreToOps
Dim oLogItem As New LogItem
Dim sDestinationFolder As String = My.Settings.DestinationFolder
Try
Dim sFileDestination As String = Path.Combine(sDestinationFolder, rFileInfo.FileName)
If File.Exists(sFileDestination) Then
File.Delete(sFileDestination)
End If
Using fs As FileStream = New FileStream(sFileDestination, FileMode.Create, FileAccess.Write, FileShare.Read)
fs.Write(rFileInfo.FileBytes, 0, rFileInfo.FileBytes.Length)
End Using
ProcessFile(rFileInfo.FileName)
Catch ex As Exception
'Error Handling
End Try
End Sub
'*************************************************************************
Private Function ProcessFile(ByVal FileName As String) As Boolean
Dim oThread As Thread = Nothing
Dim oObject As Object = Nothing
Dim oLogItem As New LogItem
Dim sDBName As String = ""
Dim bSuccess As Boolean = False
Try
If InStr(FileName, "Move.zip") > 0 Then
sDBName = Replace(FileName, "Move.zip", "")
oThread = New Thread(New ParameterizedThreadStart(AddressOf MakeRestoreFromObject))
oThread.IsBackground = True
oThread.Start(sDBName)
oThread.Join()
End If
Catch ex As Exception
'Error Handling
End Try
Return bSuccess
End Function
函数“MakeRestoreFromObject”需要相当长的时间,当使用上面的编码时,子程序在返回之前等待函数完成.....