真正同时运行两个Do Loop循环,只能靠多线程或者多进程来实现。若你正在用VB.Net里的Do Loop,那么可以很简单就能实现多线程了。 但如果你是在VB6里,只能用ActiveX.exe方式通过多个进程来实现这个同时Do Loop循环。
网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、成都微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了思明免费建站欢迎大家使用!
说起来其实并不复杂,但需要你会写VB6的Class类里的那点知识即可。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sum As Integer = 0
Dim i As Integer = 0
Do
i = i + 1
sum = sum + i
Loop Until sum 6000
MsgBox(i)
Debug.Print(sum)
End Sub
Module Module1
Sub Main()
Dim sum As Integer = 0
Dim Bound As Integer = 989
Dim num As Integer = 0
Dim cprime As Integer = 0
Do
num += 1
If IsPrame(num) Then
sum += num
cprime = num
End If
Loop Until sum Bound
Console.WriteLine(sum - cprime)
Console.ReadKey()
End Sub
'判断一个数是不是素数
Public Function IsPrame(ByVal num As Integer) As Boolean
If num = 1 Then Return False '素数的定义是大于1
For i = 2 To CType(Int(Math.Sqrt(num)), Integer)
If num Mod i = 0 Then Return False
Next
Return True
End Function
End Module
下面的代码示例说明了更改线程优先级的结果。创建两个线程,其中一个线程的优先级设置为 BelowNormal。两个线程在 while 循环中都增加一个变量,并运行一段设定的时间。
Option Explicit
Option Strict
Imports System
Imports System.Threading
Public Class Test
MTAThread _
Shared Sub Main()
Dim priorityTest As New PriorityTest()
Dim threadOne As Thread = _
New Thread(AddressOf priorityTest.ThreadMethod)
threadOne.Name = "ThreadOne"
Dim threadTwo As Thread = _
New Thread(AddressOf priorityTest.ThreadMethod)
threadTwo.Name = "ThreadTwo"
threadTwo.Priority = ThreadPriority.BelowNormal
threadOne.Start()
threadTwo.Start()
' Allow counting for 10 seconds.
Thread.Sleep(10000)
priorityTest.LoopSwitch = False
End Sub
End Class
Public Class PriorityTest
Dim loopSwitchValue As Boolean
Sub New()
loopSwitchValue = True
End Sub
WriteOnly Property LoopSwitch As Boolean
Set
loopSwitchValue = Value
End Set
End Property
Sub ThreadMethod()
Dim threadCount As Long = 0
While loopSwitchValue
threadCount += 1
End While
Console.WriteLine("{0} with {1,11} priority " _
"has a count = {2,13}", Thread.CurrentThread.Name, _
Thread.CurrentThread.Priority.ToString(), _
threadCount.ToString("N0"))
End Sub
End Class
文章名称:包含vb点虐
中loop的词条
网页URL:https://www.cdcxhl.com/article22/ddspsjc.html
成都网站建设公司_创新互联,为您提供微信公众号、做网站、动态网站、软件开发、网站营销、网站策划
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联