Thread.SetShareVar("进度值",0)
Dim 超时 = 8 //秒
Dim 主逻辑线程
Function 主逻辑函数()
Do
Dim 任务时间 = Cint(Rnd()*5)+5
Delay 任务时间 * 1000
Thread.SetShareVar "进度值", Thread.GetShareVar("进度值") + 1
TracePrint "此次任务完成,使用了"&任务时间&"秒,当前进度为:"&Thread.GetShareVar("进度值")&",重新计数"
Loop
End Function
Function 超时处理()
TracePrint "此次任务耗时超过"&超时&"秒,等待5秒后重新启动,继续上次的进度"
Thread.Stop (主逻辑线程)
Delay 5000
主逻辑线程 = Thread.Start(主逻辑函数)
End Function
Function 判断超时函数()
Dim 判定计数 = 0
Do
Dim 初始进度 = Thread.GetShareVar("进度值")
Delay 1000
If 初始进度 = Thread.GetShareVar("进度值") Then
判定计数 = 判定计数 + 1
TracePrint "超时计数器:"&判定计数
Else
判定计数 = 0
End If
If 判定计数 >= 8 Then
超时处理()
判定计数 = 0
End If
Loop
End Function
主逻辑线程 = Thread.Start(主逻辑函数)
Call 判断超时函数()