Also as a side note. When dealing with params you don't need to create the array yourself. This is handled by the compiler so you can just pass it the arguments you want from Invoke or BeginInvoke.
Example updated the StartFunctionWithProgess
Code:
public partial class Form1 : Form
{
/// <summary>
/// Delegate function to use for progess bar update(This would be what method you would want to call)
/// </summary>
/// <param name="progress">The current progress of updates</param>
private delegate void ProgessUpdateDelegate(int progress, string someValue);
/// <summary>
/// The thread for the progress update.
/// </summary>
private Thread mProgressThread;
/// <summary>
/// The delegated method for updating progess
/// </summary>
private ProgessUpdateDelegate mProgessDelegate;
public Form1()
{
InitializeComponent();
//Create the delegate for the progress update.
this.mProgessDelegate = new ProgessUpdateDelegate(this.UpdateProgressBar);
}
/// <summary>
/// This is the function you would be updating the text.
/// </summary>
private void UpdateProgressBar(int curentProgress, string someValue)
{
//Update the progress value.
this.progressBar.Value = curentProgress;
MessageBox.Show(someValue);
}
private void btnStartThread_Click(object sender, EventArgs e)
{
//
//Create the thread and start it up.
//
mProgressThread = new Thread(new ThreadStart(this.StartFunctionWithProgress));
mProgressThread.Start();
}
/// <summary>
/// This would be the function where you are threading.
/// </summary>
private void StartFunctionWithProgress()
{
//
//Function that involves proccessing. Simulating with thread sleeps.
//
//
//Note: This is where you callback to update the UI.
//
Thread.Sleep(100);
this.Invoke(this.mProgessDelegate, 20, "Woop");
Thread.Sleep(100);
this.Invoke(this.mProgessDelegate, 50, "Coolness");
Thread.Sleep(100);
this.Invoke(this.mProgessDelegate, 100, "Dude");
}
}