VB的多線程比較吃力。多個(gè)線程最后想出的辦法是用多個(gè)進(jìn)程也就是你說(shuō)的exe代替多個(gè)線程。一個(gè)form就是一個(gè)進(jìn)程你搞幾個(gè)from其實(shí)就是多進(jìn)程也就是類似的多線程但是比較麻煩點(diǎn)而已,順便給個(gè)建議VB.NET可以輕松解決多線程。
“專業(yè)、務(wù)實(shí)、高效、創(chuàng)新、把客戶的事當(dāng)成自己的事”是我們每一個(gè)人一直以來(lái)堅(jiān)持追求的企業(yè)文化。 創(chuàng)新互聯(lián)是您可以信賴的網(wǎng)站建設(shè)服務(wù)商、專業(yè)的互聯(lián)網(wǎng)服務(wù)提供商! 專注于成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、軟件開(kāi)發(fā)、設(shè)計(jì)服務(wù)業(yè)務(wù)。我們始終堅(jiān)持以客戶需求為導(dǎo)向,結(jié)合用戶體驗(yàn)與視覺(jué)傳達(dá),提供有針對(duì)性的項(xiàng)目解決方案,提供專業(yè)性的建議,創(chuàng)新互聯(lián)建站將不斷地超越自我,追逐市場(chǎng),引領(lǐng)市場(chǎng)!
調(diào)用 2.exe 用 shell 方法就可以了.不用多說(shuō).
至于檢測(cè) 5個(gè) 2.exe 是否全都結(jié)束的方法,可以在 1.exe 中添加1個(gè)TIMER ,設(shè)定每隔1秒遍歷系統(tǒng)進(jìn)程表.]
找出系統(tǒng)進(jìn)程中 2.exe 的個(gè)數(shù),若為 0個(gè) 則顯示"處理完成"
遍歷進(jìn)程需要調(diào)用API:
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const MAX_PATH As Integer = 260
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Const TH32CS_SNAPheaplist = H1
Const TH32CS_SNAPPROCESS = H2
Const TH32CS_SNAPthread = H4
Const TH32CS_SNAPmodule = H8
Public Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
'下面的"GetCount" 函數(shù)用于返回 2.exe 的個(gè)數(shù):
Public Function GetCount()
Dim i As Long, lPid As Long
Dim k As Long
Dim Proc As PROCESSENTRY32
Dim hSnapShot As Long
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '獲得進(jìn)程“快照”的句柄
Proc.dwSize = Len(Proc)
lPid = ProcessFirst(hSnapShot, Proc) '獲取第一個(gè)進(jìn)程的PROCESSENTRY32結(jié)構(gòu)信息數(shù)據(jù)
i = 0
k = 0
Do While lPid 0
If InStr(1, Proc.szExeFile, "2.exe", vbTextCompare) 0 Then
k = k + 1
End If
i = i + 1
lPid = ProcessNext(hSnapShot, Proc) '循環(huán)獲取下一個(gè)進(jìn)程的PROCESSENTRY32結(jié)構(gòu)信息數(shù)據(jù)
Loop
CloseHandle hSnapShot '關(guān)閉進(jìn)程“快照”句柄
IsDone = k
End Function
Sub Main()
Dim thr As Thread
For Pi As Integer=0 To 4 //啟用5線程
MulParams =Pi vbTab sFile vbTab dFile vbTab 1 vbTab DelN vbTab cr vbTab cg vbTab cb vbTab IndexI
GlobalParamas(pi)=MulParams .Split(vbTab)
thr=New Thread(AddressOf MyMulThreadCaller)
thr.Start() //啟動(dòng)多線程進(jìn)程
Application.DoEvents
Next
End Sub