私はこのマルチスレッドコードをvbscriptで一緒に壊してしまいましたが、私はもう一度別の問題にそれを適用しました。私は現在、実行コマンド(行20)の戻り値が常に0である問題を抱えています。私はFalse
をWaitOnReturn引数として使用したことを認識していますが、そうでなければスレッドしません。私はそれが完全に働いたと確信している、または私はずっとそれを保管していないでしょう...VBScriptスレッディング
私は間違って何を見たことができますか?
Class Thread
' Usage:
' Dim x: Set x = New Thread
' Call x.init(10)
' Call x.queue("script.bat", Array("Arg1", "output_file.txt"))
' Call x.queue("cscript.exe prog.vbs", Array("Arg1", "Arg2", "Arg3"))
' Call x.setMax(20)
''''''''''''''''''''''''''''''''''''''''''''''
Private p_threads
Private p_max
Private Function spawn(action, args)
Dim wsh: Set wsh = WScript.CreateObject("WScript.Shell")
Dim command: command = action
Dim element
For Each element In args
command = command & " " & element
Next
spawn = wsh.Run(command, 0, False)
Set wsh = Nothing
End Function
Public Sub queue(action, args)
If Ubound(p_threads,1) < p_max Then
' create new thread
ReDim Preserve p_threads(Ubound(p_threads, 1)+1)
p_threads(Ubound(p_threads, 1)) = spawn(action, args)
Else
' recycle old thread
Do
Dim i
For i = 1 To Ubound(p_threads, 1)
' find a thread which has finished
If p_threads(i) = 1 Then
p_threads(i) = spawn(action, args)
Exit Sub
End If
Next
' wait for a thread to finish
WScript.Sleep 300
Loop Until False
End If
End Sub
Public Sub init(n)
p_threads = Array(1)
p_max = n
End Sub
Public Property Let setMax(n)
p_max = n
End Property
End Class
"私はこのマルチスレッドコードをvbscriptで壊してしまいました.....私はそれが完璧に働いたと確信しています。それはずっと長く続けていないでしょう..." - 質問ではありません。 .. –
私の質問は「誰かが私が間違ったことを見ることができますか?」でした。特に20行目。 – xXhRQ8sD2L7Z