VB.NET 简单多线程多线程一般是不推荐用的,因为线程之间如果有共享资源的话会引起竞争 , 需要加锁处理;而且线程间没有时序关系,所以你在调试中可能会出现异步处理结束顺序与开始处理顺序不一致的情况(我在调试中已经发现该问题) 。
针对你提出的这个问题,采用了多线程处理,利用的是BackgroundWorker也就是异步处理控件进行了处理 。
代码已经经过调试通过 。欢迎交流,如有问题,留下QQ或其他联系方式 。
代码如下,并附程序截图 。
‘---------------------------------------------------
Imports System.ComponentModel '导入异步控件命名空间
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 * ij
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 = https://www.04ip.com/post/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 = https://www.04ip.com/post/CType(e.Result, Integer())
For i As Integer = 0 To data.Length - 1
ListBox1.Items.Add(data(i))
Next
End Sub
End Class
在vb.net中,多线程如何使用Sub Main()Dim thr As New Thread(AddressOf 循环)thr.Start("a")End SubSub 循环(a() As String)'这里随你干什么循环也行For Each i As String In aMsgBox(i)NextEnd Sub
VB.net 如何设计多线程运行Sub Main()
Dim thr As Thread
For Pi As Integer=0 To 4 //启用5线程
MulParams =PivbTabsFilevbTabdFilevbTab1vbTabDelNvbTabcrvbTabcgvbTabcbvbTabIndexI
GlobalParamas(pi)=MulParams .Split(vbTab)
thr=New Thread(AddressOf MyMulThreadCaller)
thr.Start() //启动多线程进程
Application.DoEvents
Next
End Sub
【vb.net线程的应用 vbnet中有几种线程】关于vb.net线程的应用和vbnet中有几种线程的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
推荐阅读
- 微信坊子教育公众号关注,坊子教育平台
- 硬盘模式怎么改成ahci,硬盘模式怎么修改为ahci
- cpu最高超频到什么程度,cpu最高超频到什么程度会降频
- c语言函数定义嵌套 c语言函数可以嵌套定义或者嵌套调用吗
- htmla标签不可以点击,html a 不能点击
- 生态拍摄包括什么方面,生态摄影包括哪三大类
- 鸿蒙手机服务卡片设置不了,鸿蒙手机服务卡片设置不了
- oracle帐户如何解锁 oracle账户解锁 plsql
- mongodb如何groupby,Mongodb如何启用密码复杂度策略