I need a detailed explanation of the following code line-by-line and how the flow goes, for example, when I debug. I have just used this code in my program for avoiding a cross thread access error. The code is working fine, but what is this code is all about?
delegate void updateTextField(string Text);
private void updateText(string Text)
{
if (txtDelegate.InvokeRequired)
{
updateTextField del = new updateTextField(updateText);
txtDelegate.Invoke(del, new object[] { Text });
}
else
{
txtDelegate.Text = Text;
}
}
This method is called under backgroundWorker_DoWork():
updateText("using delegate");
I also need an explanation for delegates. I read about it, but what I understood is that a delegate is like a pointer to a function, but I need a clean explanation with a simple example. Think of me as a novice.