私のアプリケーション(チャットアプリ)には3つ(メインのスレッドを数えて4つ)のスレッドがあり、各フォームを独自のスレッドに入れたいと思っています(1つのスレッドはフォームを必要としないため、関係ありません)。私が使用している2つのフォームは、ローカルデジタルフォントが含まれている時計です。問題は、threadbが起動して実行されるが、threadcはテキストLABEL1のままであり、MM / dd / yyyy hh:mm:ssttにまったく変更されないことです。これらのスレッドをどのように連携させるのか疑問に思っています。
スレッドコードは次のとおりです(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