Jamie Hartnoll
Jamie Hartnoll

Reputation: 7341

How to have a function run a callback in VB.net

I'm afraid I have been Googling this, but can't find an answer that I understand, or can use.

In Javascript, you can run a function and set a callback function which it calls after the first function has run:

function doThis(callBack){
    // do things
    // do things
    if(callBack){
         callBack();
    }
}

Call this by: doThis(function () { alert("done") });

So after it's finished doing things it calls an alert to tell you it's done.

But how do you do the same server-side in VB.NET?

Upvotes: 9

Views: 14957

Answers (1)

sloth
sloth

Reputation: 101032

Just create a method that takes an Action delegate as parameter:

Sub DoThis(callback as Action)

    'do this
    'do that

    If Not callback Is Nothing Then
        callback()
    End If

End Sub

and you can call it like

DoThis(Sub() Console.WriteLine("via callback!"))

Upvotes: 13

Related Questions