按红袍老师的指点,写了个例子,存在下面的问题:
1、如何结束后台进程。
2、任务完成后CPU利用率反而升高。
例子:
代码:
--窗口按钮事件:
Dim drs As List(Of DataRow)
drs = DataTables("TempTable").Select("[Failure] <= 2 and [success] <= 1 ")
If drs.Count > 0
MessageBox.Show(drs.Count)
Else
Return
End If
Vars("Thread_ftp") = New System.Threading.Thread(AddressOf NextFor)
LisTemp = new List(Of Object)
For Each dr1 As DataRow In drs '
Dim pName As Object = dr1("FullPath") & "|" & "医疗质量\" & FileSys.GetName( dr1("FullPath"))
LisTemp.add(pName)
Next
Vars("Thread_ftp").Start()
自定义函数
Update
Do While True
If LisTemp.Count > 0 Then
Dim ns() As String = LisTemp(0).split("|")
Dim ftp As new FTPClient
ftp.Host = ""
ftp.Account = ""
ftp.Password = ""
ftp.Port = 21
If ftp.Connect
If FileSys.FileExists(ns(0)) = True
Dim Val As String
Val = Rand.NextString(12)
val = FileSys.GetParentPath(ns(0)) & "\temp\" & val
FileSys.CopyFile(ns(0),val)
DataTables("TempTable").ReplaceFor("success",2,"FullPath = '" & ns(0) & "'")
If ftp.Upload(val,ns(1),True) = True
DataTables("TempTable").ReplaceFor("success",3,"FullPath = '" & ns(0) & "'") '3为成功,1为失败,0为等待,2为正在上传
Else
DataTables("TempTable").ReplaceFor("success",1,"FullPath = '" & ns(0) & "'")
End If
Else
DataTables("TempTable").ReplaceFor("success",1,"FullPath = '" & ns(0) & "'")
End If
End If
LisTemp.RemoveAt(0)
End If
Loop
全局代码
Default
Public LisTemp As new List(Of Object)
NextFor
Public Sub NextFor
Functions.Execute("Update")
End Sub