I'm trying to make it so that my form refreshes when I click a button. However I keep getting an error
'Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.'
private void button1_Click(object sender, EventArgs e)
{
worker.DoWork += formReload;
worker.RunWorkerAsync();
}
static BackgroundWorker worker = new BackgroundWorker();
private void formReload(object sender, DoWorkEventArgs ev)
{
this.Refresh();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
}
I've tried to research it, and I get that I have to use the Invoke method, however I don't understand where to put it, and why to use it? Any help would be much appreciated!
Thanks, Jarrod