내 상태 표시 줄에 TextBlock의 텍스트를 설정하여 잠시 기다렸다가 내 프로그램이 약간의 작업을 수행하기를 원합니다.WPF 상태 표시 줄 텍스트를 설정하는 간단한 방법이 있습니까?
Aparently, 대신 (작동하지 않습니다)이 같은 좋은 작은 기능 수행의 : 내가 대신 괴물 사용해야
Function Load(ByVal Id As Guid) As Thing
Cursor = Cursors.Wait
TextBlockStatus.Text = "Loading..."
TextBlockStatus.UpdateLayout()
Dim Found = From t In db.Thing _
Where t.Id = Id _
Select t
TextBlockStatus.Text = String.Empty
Cursor = Cursors.Arrow
Return Found
End Function
을 :
Private WithEvents LoadWorker As BackgroundWorker
Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
InitializeLoadWorker()
End Sub
Private Sub InitializeLoadWorker()
LoadWorker = New BackgroundWorker
LoadWorker.WorkerSupportsCancellation = False
LoadWorker.WorkerReportsProgress = False
AddHandler LoadWorker.DoWork, AddressOf LoadBackgroundWorker_DoWork
AddHandler LoadWorker.RunWorkerCompleted, AddressOf LoadBackgroundWorker_RunWorkerCompleted
End Sub
Sub Load(ByVal Id As Guid)
Cursor = Cursors.Wait
LoadWorker.RunWorkerAsync(Argument)
End Sub
Private Sub LoadBackgroundWorker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim Worker As BackgroundWorker = DirectCast(sender, BackgroundWorker)
Dim Id As Guid = DirectCast(e.Argument, Guid)
e.Result = From t In db.Thing _
Where t.Id = Id _
Select t
End Sub
Private Sub LoadBackgroundWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
TextBlockStatus.Text = String.Empty
Cursor = Cursors.Arrow
Dim Found As Thing = DirectCast(e.Result, Thing)
'now do something with the found thing here instead of where Load() is called.'
End Sub
그리고로드() 함수 지금은 Sub입니다!
이러한 간단한 상황을 처리하는 더 좋은 방법이 있어야합니다. 이것은 비동기 일 필요는 없습니다.
왜 작동하지 않습니다이 VB.NET을 위해 작동 할 수 있습니다 (그래도 난 그것을 시도하지 않은)? –
텍스트가 업데이트되지 않습니다. –