'定义委托
Delegate Sub Gxdjs(ByVal data As String)
Private Sub UpdateStatus(ByVal n As String)
Dispatcher.Invoke(New Gxdjs(AddressOf Cdjs), n) '用Invoke跨线程更新UI
End Sub
Private Sub Cdjs(ByVal data As String) '这里要和委托定义时的参数保持一致
lb_Status.Text = data
End Sub
'引用
Dim Msg As String = "正在下载" + filename + "......"
UpdateStatus(Msg)
APP.DoEvents()
Imports System.Windows.Threading
Partial Class APP
Inherits Application
Private Shared exitFrameCallback As New DispatcherOperationCallback(AddressOf ExitFrame)
Public Shared Sub DoEvents()
Dim nestedFrame = New DispatcherFrame()
Dim exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, exitFrameCallback, nestedFrame)
Dispatcher.PushFrame(nestedFrame)
If exitOperation.Status <> DispatcherOperationStatus.Completed Then
exitOp