Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

VS 2013 Manipulating execution of cutom events

$
0
0
Hey guys.

Is it possible to manipulate the order of execution from the "Raise Event" function of Custom events? It could be done by adding each "handler" to a collection and executing them asynchronously but I couldn't manage to do it myself.

Here is how my code looks like:

Code:

Class MainWindow
    Private WithEvents EventTest As New Events
    Private Sub Form_load(ByVal sender As Object, e As EventArgs) Handles Me.Loaded
        AddHandler EventTest.Go, AddressOf Run1
        AddHandler EventTest.Go, AddressOf Run2
        AddHandler EventTest.Go, AddressOf Run3
    End Sub

    Private Sub Run1()
        Debug.Print("1")
    End Sub
    Private Sub Run2()
        Debug.Print("2")
    End Sub
    Private Sub Run3()
        Debug.Print("3")
    End Sub

    Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
        EventTest.ExecuteEvent()
    End Sub
End Class
Public Class Events
    Public Delegate Sub GoEventHandler()
    Private mGoHandlers As GoEventHandler

    Public Sub ExecuteEvent()
        RaiseEvent Go()
    End Sub

    Public Custom Event Go As GoEventHandler
        AddHandler(value As GoEventHandler)
            mGoHandlers = CType([Delegate].Combine(mGoHandlers, value), GoEventHandler)
        End AddHandler

        RemoveHandler(value As GoEventHandler)
            mGoHandlers = CType([Delegate].Remove(mGoHandlers, value), GoEventHandler)
        End RemoveHandler

        RaiseEvent()
            If mGoHandlers IsNot Nothing Then
                mGoHandlers.Invoke()
            End If
        End RaiseEvent
    End Event
End Class

Say I need to execute Run3 then Run2 then Run1 without changing the order of the Add Handlers.

Thank you in advance,
Dave.

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>