成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

vb.net多進(jìn)程 windows多進(jìn)程編程

VB.net 如何設(shè)計(jì)多線程運(yùn)行

Sub Main()

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比張家川回族自治網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式張家川回族自治網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋張家川回族自治地區(qū)。費(fèi)用合理售后完善,十年實(shí)體公司更值得信賴。

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

vbnet同時(shí)執(zhí)行多個(gè)任務(wù)

題主是否想詢問“vbnet同時(shí)執(zhí)行多個(gè)任務(wù)怎么實(shí)現(xiàn)”?多線程操作。vbnet同時(shí)執(zhí)行多個(gè)任務(wù)通過多線程操作實(shí)現(xiàn),Visual Basic.net,屬于計(jì)算機(jī)軟件領(lǐng)域,是計(jì)算機(jī)中實(shí)現(xiàn)網(wǎng)絡(luò)功能的編程語(yǔ)言。

VB.NET 簡(jiǎn)單多線程

多線程一般是不推薦用的,因?yàn)榫€程之間如果有共享資源的話會(huì)引起競(jìng)爭(zhēng),需要加鎖處理;而且線程間沒有時(shí)序關(guān)系,所以你在調(diào)試中可能會(huì)出現(xiàn)異步處理結(jié)束順序與開始處理順序不一致的情況(我在調(diào)試中已經(jīng)發(fā)現(xiàn)該問題)。

針對(duì)你提出的這個(gè)問題,采用了多線程處理,利用的是BackgroundWorker也就是異步處理控件進(jìn)行了處理。

代碼已經(jīng)經(jīng)過調(diào)試通過。歡迎交流,如有問題,留下QQ或其他聯(lián)系方式。

代碼如下,并附程序截圖。

‘---------------------------------------------------

Imports?System.ComponentModel?'導(dǎo)入異步控件命名空間

Public?Class?Form1

Private?howmany?As?Integer?=?10

Private?AnalysisNumber(0?To?howmany?-?1)?As?BackgroundWorker

Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click

ListBox1.Items.Clear()

creatNewBackgroundWorker()

addHandle()

startWork()

End?Sub

Private?Sub?creatNewBackgroundWorker()

For?i?As?Integer?=?0?To?AnalysisNumber.Length?-?1

AnalysisNumber(i)?=?New?BackgroundWorker

Next

End?Sub

Private?Sub?addHandle()

For?i?As?Integer?=?0?To?AnalysisNumber.Length?-?1

AddHandler?AnalysisNumber(i).DoWork,?AddressOf?AnalysisNumber_DoWork

AddHandler?AnalysisNumber(i).RunWorkerCompleted,?AddressOf?AnalysisNumber_RunWorkerCompleted

Next

End?Sub

Private?Sub?startWork()

For?i?As?Integer?=?0?To?9

Dim?temp(0?To?9)?As?Integer

For?j?As?Integer?=?1?To?10

temp(j?-?1)?=?10?*?i?+?j

Next

AnalysisNumber(i).RunWorkerAsync(temp)

Next

End?Sub

Private?Sub?AnalysisNumber_DoWork(ByVal?sender?As?Object,?ByVal?e?As?System.ComponentModel.DoWorkEventArgs)

Dim?data?As?Integer()

data?=?CType(e.Argument,?Integer())

Dim?temp?As?Integer

For?i?As?Integer?=?0?To?data.Length?-?1

temp?=?data(i)

data(i)?=?temp?*?temp

Next

e.Result?=?data

End?Sub

Private?Sub?AnalysisNumber_RunWorkerCompleted(ByVal?sender?As?Object,?ByVal?e?As?System.ComponentModel.RunWorkerCompletedEventArgs)

Dim?data?As?Integer()

data?=?CType(e.Result,?Integer())

For?i?As?Integer?=?0?To?data.Length?-?1

ListBox1.Items.Add(data(i))

Next

End?Sub

End?Class

Vb 多進(jìn)程技術(shù)

調(diào)用 2.exe 用 shell 方法就可以了.不用多說.

至于檢測(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

名稱欄目:vb.net多進(jìn)程 windows多進(jìn)程編程
文章地址:http://jinyejixie.com/article8/hehiop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)App開發(fā)、營(yíng)銷型網(wǎng)站建設(shè)標(biāo)簽優(yōu)化、網(wǎng)站建設(shè)、全網(wǎng)營(yíng)銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司
苗栗县| 自治县| 丹阳市| 阿拉尔市| 华坪县| 西和县| 盐边县| 西和县| 南丹县| 垫江县| 休宁县| 五莲县| 建宁县| 合水县| 永兴县| 偏关县| 双桥区| 宝坻区| 松滋市| 兴安盟| 三明市| 梧州市| 永登县| 鞍山市| 建宁县| 平度市| 开平市| 余庆县| 贺兰县| 高尔夫| 鄂尔多斯市| 犍为县| 泸州市| 台前县| 济宁市| 利辛县| 昆山市| 昌黎县| 望谟县| 全南县| 社会|