Your problem is that your control exists on thread A but you are trying to access it via thread B. This is a 'no-no'. Try the following code
private void btnSend_Click(object sender, EventArgs e)
{
Task.Run(() => LoadData(System.Threading.SynchronizationContext.Current, progressBar1));
}
private void LoadData (System.Threading.SynchronizationContext synchContext, ProgressBar1ObjectType progressBar)
{
string filePath = tbPath.Text;
ETLBusiness etlBusiness = new ETLBusiness(filePath);
synchContext.Post(state => etlBusiness.LoadData(progressBar), null);
}
Where 'ProgressBar1ObjectType' is the Type of progressBar1
Here is another option that may work better:
Thread _myThread = null;
private void btnSend_Click(object sender, EventArgs e)
{
SynchronizationContext synchContext = SynchronizationContext.Current;
_myThread = new Thread(() => LoadData(synchContext, progressBar1));
myThread.Start();
}
private void LoadData (System.Threading.SynchronizationContext synchContext, ProgressBar1ObjectType progressBar)
{
string filePath = tbPath.Text;
ETLBusiness etlBusiness = new ETLBusiness(filePath);
synchContext.Post(state => etlBusiness.LoadData(progressBar), null);
_myThread.Abort();
}