9

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?

Chad
  • 1,531
  • 3
  • 20
  • 46
Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97

1 Answers1

13

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!"))
sloth
  • 99,095
  • 21
  • 171
  • 219