Callbacks by nature aren't simple. Here's a contrived sample that uses one,
but it's not very useful. Typically they're helpful in multithreaded
situations or where you're using polymorphism and/or inheritance. I'm not
going to slap a sample of that together, as it would take a while, and if
you don't understand what a callback is, you're probably not going to
understand the sample without research. I recommend you do some Googling on
delegates to see how they work and what they're used for. You'll find a
plethora of useful stuff out there.
Anyway, here's a quick, useless example:
delegate void CallbackDelegate(int val);
void Method()
{
DoWork();
OtherMethod(new CallbackDelegate(CallbackProc));
DoMoreWork();
}
void CallbackProc(int val)
{
MessageBox.Show("Callback " + val);
}
void OtherMethod(CallbackDelegate callback)
{
DoStuff();
for(int i = 0 ; i < 5 ; i++)
{
callback(i);
}
DoMoreStuff();
}
--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate