I wanted to post up a tut so I made these functions real quick. Note that delegating is only required when trying to edit a form control that was created on a different thread. If anybody needs any help with this don't hesitate to ask.
Usings:
Code:
using System.Threading;
Code:
Code:
private void callThreadedFunction()
{
new Thread(new ThreadStart(threadedFunction)).Start();
}
private void threadedFunction()
{
// Do big processing that would normally make the GUI not respond
delegatedFunction("Changed From Thread"); // Call to delegated function since you can't interact with forms from different thread
}
private delegate void delegatedFunctionD(string setText); // A delegate is a callback
private void delegatedFunction(string setText)
{
// Invoking just sends a message to the forms message pump so it can be called from the initial thread
if (InvokeRequired)
{
BeginInvoke(new delegatedFunctionD(delegatedFunction), new object[] { setText });
return; // Don't continue if we are in different thread and Invoke is required
}
// This is called in the initial thread
this.Text = setText;
}