vb.net多进程程序 vbnet多线程简单

VB多进程怎么做?。烤褪悄歉錾禷ctivex exe的 , 能详细一点吗?VBvb.net多进程程序的多线程比较吃力 。多个线程最后想出的办法是用多个进程也就是你说的exe代替多个线程 。一个form就是一个进程你搞几个from其实就是多进程也就是类似的多线程但是比较麻烦点而已vb.net多进程程序 , 顺便给个建议VB.NET可以轻松解决多线程 。
vb.net里如何设置多线程?首先,你把你那些要运行很久的过程 。尽量放在一个过程中 。
因为线程只能是过程,不能使函数,没有返回值的 。
然后,在某个事件下这样写:
**这里我假设你的那个很就的过程叫做 sub aaa()
调用如下:
Dim mythread As New System.Threading.Thread(AddressOf aaa)
mythread.Start()
***********
这样就是定义一个线程,名字叫 mythread,这个线程会运行aaa这个过程 。
start 就是让线程运行 。
Vb 多进程技术调用 2.exe 用 shell 方法就可以了.不用多说.
至于检测 5个 2.exe 是否全都结束的方法,可以在 1.exe 中添加1个TIMER ,设定每隔1秒遍历系统进程表.]
找出系统进程中 2.exe 的个数,若为 0个 则显示"处理完成"
遍历进程需要调用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
【vb.net多进程程序 vbnet多线程简单】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" 函数用于返回 2.exe 的个数:
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) '获得进程“快照”的句柄
Proc.dwSize = Len(Proc)
lPid = ProcessFirst(hSnapShot, Proc) '获取第一个进程的PROCESSENTRY32结构信息数据
i = 0
k = 0
Do While lPid0
If InStr(1, Proc.szExeFile, "2.exe", vbTextCompare)0 Then
k = k + 1
End If
i = i + 1
lPid = ProcessNext(hSnapShot, Proc) '循环获取下一个进程的PROCESSENTRY32结构信息数据
Loop
CloseHandle hSnapShot '关闭进程“快照”句柄
IsDone = k
End Function
求教VB.net多线程问题多线程是用于处理复杂项目的
打个比方
你的主程序线程A中有个循环,由于代码是一行行走的,所以循环结束前下面的代码无法运行,而此时主界面的反应就类似卡死的样子,你点击按钮也没有反应,因为主线程在忙着循环呢,所以对按钮的事件代码要等待了 , 如果要避免这种情况 , 就要用到多线程 , 另开一个新线程专门用来执行循环代码,主界面就不会卡死了,只要在循环结束后将结果传回主线程调用就可以了,再复杂点要涉及到委托,控制了

推荐阅读