How to use Control.Dispatcher.BeginInvoke to modify GUI
<p>I need to modify the GUI from inside of a method that takes long time to finish. As I read other posts,
one of the solution is to use Control.Dispatcher.BeginInvoke to set the GUI inside the worker thread.
However, I don't have a clue how to do this here.</p>

<pre><code>public partial class MainForm : Form
{
    public MainForm()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Task.Factory.StartNew( () =&gt;
        {
            ProcessFilesThree();
        });
    }

    private void ProcessFilesThree()
    {
        string[] files = Directory.GetFiles(@"C:\temp\In", "*.jpg", SearchOption.AllDirectories);

        Parallel.ForEach(files, (currentFile) =&gt;
        {
            string filename = Path.GetFileName(currentFile);

                    // the following assignment is illegal
            this.Text = string.Format("Processing {0} on thread {1}", filename,
                                        Thread.CurrentThread.ManagedThreadId); 
        });

        this.Text = "All done!"; // &lt;- this assignment is illegal
    }
}
</code></pre>
