
imports System.Threadingimports SystemPublic Class Form1 Dim th1,th2 As Thread Public Sub Method1() Dim i As Integer For i = 1 To 100 If Me.Label1.Backcolor = color.DarkRed Then Me.Label1.Backcolor = color.Gold End If System.Threading.Thread.Sleep(100) If Me.Label1.Backcolor = color.Gold Then Me.Label1.Backcolor = color.DarkRed End If System.Threading.Thread.Sleep(100) Next End Sub Public Sub Method2() Dim i As Integer For i = 1 To 100 If Me.Label2.Backcolor = color.DarkRed Then Me.Label2.Backcolor = color.Gold End If System.Threading.Thread.Sleep(500) If Me.Label2.Backcolor = color.Gold Then Me.Label2.Backcolor = color.DarkRed End If System.Threading.Thread.Sleep(500) Next End Sub Private Sub button1_Click(sender As Object,e As EventArgs) Handles button1.Click Me.Label1.Backcolor = color.DarkRed Me.Label2.Backcolor = color.DarkRed th1 = New Thread(New ThreadStart(AddressOf Method1)) th1.Start() th2 = New Thread(New ThreadStart(AddressOf Method2)) th2.Start() System.Threading.Thread.Sleep(1000) End Sub Private Sub Form1_Load(sender As Object,e As EventArgs) Handles Me.FormClosed th1.Abort() ‘ 调用此方法通常会终止线程。 th2.Abort() End SubEnd Class总结
以上是内存溢出为你收集整理的VB.net 与线程全部内容,希望文章能够帮你解决VB.net 与线程所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)