That's a great tip!
But this code doesn't compile:
/// <summary>
/// A button on the form
/// </summary>
private void button1_Click(object sender, System.EventArgs e)
{
delegateInstance = new ExampleDelegate(beginThink);
d.BeginInvoke(5, new AsyncCallback(finished), null);
}
it should be:
/// <summary>
/// A button on the form
/// </summary>
private void button1_Click(object sender, System.EventArgs e)
{
delegateInstance = new ExampleDelegate(beginThink);
delegateInstance.BeginInvoke(5, new AsyncCallback(finished), null);
}
Question: I'm not sure I quite understand this sentence from your post:
"This is a short sharp example, and can be created in a simple form. Remember not to try to update the form from the method being run by the delegate - if you want to do this you need to run a method that checks if InvokeRequired is true, then runs Invoke(myMethodsOwnName, new object {myFirstParameter, mySecondParameter, andSoOn}) if it is true, or does whatever UI editing is needed if false - so it is calling itself in the context of the user interface. "
I did adapt your sample for my form to start asynchronously a "CPU hog" thread - it works OK, my form doesn't block and I can set this form's title and the values of its controls by using direct delegate call from asynchronously running thread. Is that OK? Or it may result in some problems and this is what you are talking about when mentioning "InvokeRequired" etc...
Thanks you,
Shamil