나는 창문 양식 응용 프로그램을 가지고 있으며, 두 개의 "프로세스"표시기를 만들고 싶습니다. 배경색 (녹색, 빨간색) 및 표시된 텍스트 ("OK", "...")를 사용하여 하위 또는 기능이 실행 중인지 여부를 나타 내기 위해 레이블을 사용하고 싶습니다.레이블 백 색이 준비 상태로 변경됩니다. VB.NET
다음은이 간단한 코드입니다. "표시기"레이블 컨트롤은 "Label1
"입니다. "GridRefresh
"과 비슷한 기능과 서브가 있습니다.
하위의 시작 부분에서 Label을 빨간색으로 설정하고 끝 부분을 녹색으로 설정하고 싶습니다.
내 문제는 라벨이 절대로 빨간색으로 바뀌지 않는다는 것입니다. 예를 들어, GridRefresh
은 500-1000ms 동안 실행됩니다. If Then Else
에 2000ms의 잠자기를 시도했지만 아무 것도 변경되지 않았습니다.
Sub GridRefresh()
ReadySwitch(False)
'--do something
....
ReadySwitch(True)
End Sub
Sub ReadySwitch(ready As Boolean)
If ready Then
Label1.BackColor = Color.LightGreen
Label1.Text = "OK"
Else
Label1.BackColor = Color.Red
Label1.Text = "..."
End If
End Sub
멀티 스레딩을 시도했지만 동일한 효과가 있습니다.
InvokeRequired - state: False InvokeRequired - state: True LabelChange - state: False LabelChange - color: Red LabelChange - state: True LabelChange - color: LightGreen
내가 잘못 무엇을 :
이 경우Sub GridRefresh()
ReadySwitch(False)
'--do something
....
ReadySwitch(True)
End Sub
Sub ReadySwitch(ready As Boolean)
LabelReadyCall(ready)
End Sub
Public t1 As System.Threading.Thread
Sub LabelReadyCall(ByVal ready As Boolean)
t1 = New System.Threading.Thread(AddressOf Me.LabelReadyExecute)
t1.Start(ready)
End Sub
Private Delegate Sub LabelReadyDelegate(ByVal ready As Boolean)
Sub LabelReadyExecute(ByVal ready As Boolean)
If Label1.InvokeRequired Then
Debug.Print("InvokeRequired - state: " & ready)
Label1.BeginInvoke(New LabelReadyDelegate(AddressOf LabelReadyExecute), New Object() {ready})
Else
If ready Then
Label1.BackColor = Color.LightGreen
Label1.Text = "OK"
Else
Label1.BackColor = Color.Red
Label1.Text = "..."
End If
Debug.Print("LabelChange - state: " & ready)
Debug.Print("LabelChange - color: " & Label1.BackColor)
End If
End Sub
출력 윈도우의 내용이 무엇입니까? 멀티 스레딩에 대한
멀티 스레딩을 사용하는 경우 변경 직후에 하나의 스레드에서 '호출'해야 할 필요가 있습니다 :'' Application.DoEvents()' – Mederic