This is because you are doing all the processing in the Load event for the form . This is called before the form is shown for the first time.
In the event handler, you actually forbid the display of the form, since the event handler must complete before anything else is processed.
What you would like to do is use BackgroundWorker to do your work. To do this, you need to follow these steps:
You have some problems with having your Pizza class closely related to the progress bar. This is not a good idea. Rather, you should have an event that will fire to indicate that the progress has been changed, and then raise the ProgressChanged event from the event handler for your Pizza instance.
I moved the code for your Eat method and encapsulated it in a form to show you an example of using the BackgroundWorker class, but the ideal solution would be to expose the event to indicate when the number of pizza consumed changes.
Also note that you must override the protected Dispose method in the form class in order to properly get rid of the BackgroundWorker instance when the form is deleted.
Here is an example:
public void SpawnPizzaProgressBarForm(object sender, EventArgs e) { FormPizzaProgressBar Form = new FormPizzaProgressBar(); Form.ShowDialog(); } ... BackgroundWorker worker = new BackgroundWorker(); public void ProgressBarForm_Load(object sender, EventArgs e) {
source share