by Papa » 2020年1月23日(木) 09:55
GetExitCodeThreadにてスレッドの終了を見つけられ下記の様にしました。
これがスレッドプールと同じかどうかわかりませんが解決しました。
ありがとうございました。
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]
Dim hthMain(100) As HANDLE
Dim ThCunte As Byte
Sub MainWnd_Destroy()
time_DestroyObjects()
PostQuitMessage(0)
End Sub
Sub MainWnd_Create(ByRef CreateStruct As CREATESTRUCT)
SetTimer(hMainWnd,100,1000,0)
ThCunte = 0
End Sub
Sub MainWnd_Timer(TimerID As DWord)
Dim tID As Dword
Dim hCreateThread As HANDLE
hCreateThread = CreateThread(ByVal 0,0,AddressOf(tim_sub),0,0,VarPtr(tID))
Dim cunt As Byte
'空いているhthMain()にThread Handleを保存
For cunt = 1 To 100
If hthMain(cunt) = 0 Then
hthMain(cunt) = hCreateThread
Exit For
End If
Next
'終了しているThread HandleをCloseする。
Dim ecode As DWord
For cunt = 1 To 100
If GetExitCodeThread(hthMain(cunt), ecode ) <> 0 Then
If ecode <> STILL_ACTIVE Then
CloseHandle(hthMain(cunt)) ' スレッドハンドルを閉じる
hthMain(cunt) = 0
End If
End If
Next
End Sub
Sub tim_sub()
'実際の処理時間はまちまちなので、今回は乱数Sleepで代用
Randomize
Sleep(Int(Rnd()*10)*500)
End Sub
GetExitCodeThreadにてスレッドの終了を見つけられ下記の様にしました。
これがスレッドプールと同じかどうかわかりませんが解決しました。
ありがとうございました。
[hide]
Dim hthMain(100) As HANDLE
Dim ThCunte As Byte
Sub MainWnd_Destroy()
time_DestroyObjects()
PostQuitMessage(0)
End Sub
Sub MainWnd_Create(ByRef CreateStruct As CREATESTRUCT)
SetTimer(hMainWnd,100,1000,0)
ThCunte = 0
End Sub
Sub MainWnd_Timer(TimerID As DWord)
Dim tID As Dword
Dim hCreateThread As HANDLE
hCreateThread = CreateThread(ByVal 0,0,AddressOf(tim_sub),0,0,VarPtr(tID))
Dim cunt As Byte
'空いているhthMain()にThread Handleを保存
For cunt = 1 To 100
If hthMain(cunt) = 0 Then
hthMain(cunt) = hCreateThread
Exit For
End If
Next
'終了しているThread HandleをCloseする。
Dim ecode As DWord
For cunt = 1 To 100
If GetExitCodeThread(hthMain(cunt), ecode ) <> 0 Then
If ecode <> STILL_ACTIVE Then
CloseHandle(hthMain(cunt)) ' スレッドハンドルを閉じる
hthMain(cunt) = 0
End If
End If
Next
End Sub
Sub tim_sub()
'実際の処理時間はまちまちなので、今回は乱数Sleepで代用
Randomize
Sleep(Int(Rnd()*10)*500)
End Sub
[/hide]