I want to show a new Form with a Progressbar while my MainForm is doing some database related work. I've read that you don't want to pass the UI to a new thread, so I'm wondering what the best solution is to get around this problem?
I can't do the database related work on another thread since it uses a dozen calls to the UI and to the MainForm. I also can't use Application.DoEvents()
since the MainForm's thread is working inside a class, and as far as I know you shouldn't do any calls to the parent of the class.
Any suggestions would be appreciated!
Edit
To clarify what I was actually wondering:
My Program looks kinda like this:
... Content = DatabaseClass.LoadContent();
ApplyContentToUI(Content);
And what I wanted to do was the following:
//Show a form here with a progressbar
... Content = DatabaseClass.LoadContent();
ApplyContentToUI(Content);
//Close the form here
But since the time to execute ApplyContentToUI was aprox. 1 second I descided to do the following:
//Show a form here with a progressbar
... Content = DatabaseClass.LoadContent();
//Close the form here
ApplyContentToUI(Content);
If you, unlike me, need to show the Progressbar while reloading the UI I suggest that you look at the comments and answers below.