我的应用程序(聊天应用程序)中有三个(4 个计数主要线程)线程,我想将每个表单放入它自己的线程中(一个线程不需要表单,因此无关紧要)。我正在使用的两种形式是带有本地数字字体的时钟。问题是 threadb 将启动并运行,但 threadc 将保留为文本 LABEL1 并且根本不会更改为:MM/dd/yyyy hh:mm:ss tt。我想知道如何让这些线程一起工作。
这是线程代码(在 porgram 开头创建,这是来自 sub official_start):
threadb = New Threading.Thread(AddressOf form3threadsub)
threadc = New Threading.Thread(AddressOf form4threadsub)
threadb.IsBackground = False
threadc.IsBackground = False
threadb.Start()
threadc.Start()
这是线程潜艇的代码:
Private Sub form3threadsub()
Dim first As Boolean = False
Do
System.Threading.Thread.Sleep(100)
If first = False Then
form3.ShowDialog()
first = True
End If
form3.Label1.Text = DateTime.UtcNow.ToString("MM/dd/yyyy hh:mm:ss tt")
form3.Update()
Loop
End Sub
Private Sub form4threadsub()
Dim first As Boolean = False
Do
System.Threading.Thread.Sleep(100)
If first = False Then
Form4.ShowDialog()
first = True
End If
Form4.Label1.Text = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")
Form4.Update()
Loop
End Sub
这是button2点击:
Dim clicked As Boolean = True
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If clicked Then
threadb.Suspend()'obsolete
threadc.Suspend()'obsolete
Button2.Text = "Resume Clocks"
clicked = False
Else
threadb.Resume()'obsolete
threadc.Resume()'obsolete
Button2.Text = "Pause Clocks"
clicked = True
End If
End Sub