none
vb2008中异步调用,如何取消? RRS feed

  • 问题

  • 这是一个控件中实现异步回调的,我想在该控件dispose是终止未完成的异步调用

    '触发异步回调函数   

     Public Sub RefreshText()

            Dim handler As New EditData.ReadvalueDelegate(AddressOf EditData.Readvalue)

            Dim result As IAsyncResult = handler.BeginInvoke(ConSQL, Constr, New AsyncCallback(AddressOf ReadValueComplete), handler)

        End Sub

    异步调用函数

        Private Sub ReadValueComplete(ByVal result As IAsyncResult)

            Dim handler As EditData.ReadvalueDelegate = DirectCast(DirectCast(result, AsyncResult).AsyncDelegate, EditData.ReadvalueDelegate)

            setText(handler.EndInvoke(result).ToString())

        End Sub

        Public Delegate Sub SetTextCallback(ByVal Value As String)

        ' 取值函数

        Private Sub setText(ByVal Value As String)

            If Me.InvokeRequired Then

                Dim s As New SetTextCallback(AddressOf setText)

                Invoke(s, New String() {Value})

            Else

                Me.Text = "有" & Value & Destrip

            End If

        End Sub

    2010年9月8日 3:12

答案