我有以下代码,但它最初不会更新UI线程。我做错了吗?
Protected Sub Copy_OnClick(sender As Object, e As EventArgs)
StatusLabel.Text = "Processing..." 'This doesn't happen
Copy.Enabled = False 'This doesn't happen
Dim copyTask As Task = Task.Factory.StartNew(Sub() Copy())
copyTask.Wait()
If (copyTask.IsCompleted) Then
Copy.Enabled = True
StatusLabel.Text = "Done" 'This happens
End If
End Sub
答案 0 :(得分:2)
是的,您正在等待UI线程。你为什么要开始一项任务然后立即等待呢?这在概念上没有意义。
使用其中一种标准技术来解锁UI线程。