imho the key aspect of what a "callback"
is ... is:
executable code that is written in a form where it can be
passed as a parameter to some other method which can then
execute the code.
It is typical to refer to the execution of the code in a callback as "invocation."
Different languages vary in
how they implement this functionality: for example, a common description outside the .NET "world" would be: to pass a pointer to a function. But, .NET was designed not to make explicit use of pointers.
Keep in mind that .NET doesn't formally distinguish between the terms "function" and "method," as many other languages do.
Another frequent term in describing the operational behavior of callbacks is:
deferred execution. In .NET you can think of creating Delegates as being a way to encapsulate executable code, and then "hand it off" to other methods that use the code.
I think an example may be useful:
Assume: you have two TextBoxes on a Form, 'textBox1, 'textbox2, a Button, 'SomeButton
private void SomeButton_Click(object sender, EventArgs e)
{
Func<int, int, string> ReturnStringCallBack = (x, y) =>
{
return textBox1.Text
+ " " + x.ToString()
+ " " + textBox2.Text
+ " " + y.ToString();
};
string result = executeFunc(100, 200, ReturnStringCallBack);
MessageBox.Show(result);
}
private string executeFunc(int x, int y, Func<int, int, string> theCallBack)
{
System.Threading.Thread.Sleep(4000);
return theCallBack(x,y);
}
The key thing here is that you understand that you can compose a unit of executable code as needed and pass it to some external method/context for deferred, any-time, execution (invocation), and that after the unit of code's deferred execution
control will return to the method/context in which the callback originated.
If your delegate (unit of executable code) returns a value, as any delegate created using the 'Func notation does, then you can use the value returned in the code that defined the delegate.
For creating a unit of code (delegate) to be passed as a parameter that does not return a value, you can use the 'Action notation.