c# - Progress Bar Only Appears After Work Is Complete? -


I'm trying to show a progress bar on a form, but for some reason this form does not actually appear Until the process is finished, and when the process is finished (or in other words, this form is only open for a moment) stops, how can I make it so that the form at the beginning of the form To be shown?

Note: My code can not be 100% correct, I am just trying to isolate it from myself for privacy reasons.

  Public Zero SpawnPizzaProgressBarForm (Object Sender, EventArgs E) {FormPizzaProgressBar Form = New FormPizzaProgressBar (); Form.ShowDialog (); } ... Public Zero ProgressBarForm_Load (Object Sender, EventArgs E) {Pizza = New Pizza (); Pizza.Eat (PizzaEatingProgressBar); This.Close (); } ... Public Zero Eats (Progressive Pizzaing Progress Maintained) {foreach (Everything in Pizza) {slice.Clear (); // PizzaEatingProgressBar.Value = (Slice.Index / Pizza.Count ()) * 100}}  
post = "post-text" itemprop = "text" >

This happens because you do all the processing. This is called before for the first time.

When in the event handler, you are actually blocking the form from being displayed, because the event handler must first be completed, anything can be processed.

What you want to do, use an example to do your work, for this you have to do the following:

  • set to true (Default is false)
  • Subscribe to
  • in DoWork event handler, call to report your progress
  • Subscribe, this is it Is the place where you will update your progress times
  • This is also the event htat is removed while calling ReportProgrs method mentioned earlier
  • Subscribe, this is where you will close your form
  • Asynchronous operation

You have some problems with which you can get your pizza class tightly in progress times. It is not a good idea, instead you should have such an event. Need to change the progress that has been removed to indicate Call EVE, and then call the event by changing progress with event handler for your pizza example.

I have removed the code for your food method and it has been explained in the form to show you an example of using the background worker class, but the ideal solution will be to disclose an event when the pizza The amount of change occurs.

Also keep in mind that

Public Zero SpawnPizzaProgressBarForm (Object Provider, EventArggs E) {Form Peugeot Bursor Form = New FormPagePrepressBar (); Form.ShowDialog (); } ... background worker = new backgroundwork (); Public Zero ProgressBarForm_Load (Object Sender, EventArgs E) {// Background Worker Worker = New BackgroundWorkwork (); // Notify that worker support progresses Worker.WorkerSupports progress = true; // Subscribe to DoWork event Worker.DoWork + = (s, e) = & gt; {// Pizza Example Make Pizza = New Pizza (); // Process Slices Forhcha (Cheese Slice in Pizza) {// Slice Clear Clear Slice.Clear (); // Report progress worker Report progress (slice index / pizza.count () * 100); }}; // Subscribe to event of progress change. By changing progress = (S, E) => {// Update progress bar PizzaEatingProgressBar.Value = E. Progress report; }; // subscribe to RunWorkerCompleted event. Worker.RunWorkerCompleted = (s, e) = & gt; {// Close Displacement this.Close (); }; } / / Background worker should be override to handle properly. Call Protected Override Zero Dispos (Bull Displacement) {// Base. Base.Disposing (settlement); // Settlement is true if the settlement of the background worker. If (settlement) employees Conflict (); }


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -