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?
A custom callback function can be created by using the callback keyword as the last parameter. It can then be invoked by calling the callback() function at the end of the function. The typeof operator is optionally used to check if the argument passed is actually a function. console.
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. The above example is a synchronous callback, as it is executed immediately.
To implement a callback functionCreate the managed callback function. The example declares a delegate type, called CallBack , which takes two arguments (hwnd and lparam). The first argument is a handle to the window; the second argument is application-defined. In this release, both arguments must be integers.
A callback function is a function that occurs after some event has occurred. The reference in memory to the callback function is usually passed to another function. This allows the other function to execute the callback when it has completed its duties by using the language-specific syntax for executing a function.
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!"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With