I was looking at an MSDN about RegisterWaitForSingleObject
HERE and found this usage in the example -
ti.Handle = ThreadPool.RegisterWaitForSingleObject(
ev,
new WaitOrTimerCallback(WaitProc),
ti,
1000,
false
);
Where WaitProc
is a method -
public static void WaitProc(object state, bool timedOut)
{
//Code
}
I also found examples where the same by replacing WaitProc
method to something similar to this -
ti.Handle = ThreadPool.RegisterWaitForSingleObject(
ev,
(state, timedOut) => {
//code blah blah
//manipulate state
//manipulate timedOut
}
ti,
1000,
false
);
Here I'm assuming the method RegisterWaitForSingleObject
expects a WaitOrTimerCallback
method, and compiler understand this and considers (state, timedOut)
as the method, and hence the variables can be used within the call itself.
What is this concept called?
And how does it work?