winforms - Using ProgressBar as a wait bar - how to avoid freezes? -


I am creating a custom charting control and I am likely to display some waiting times while others order (I.e. the chart is being created).

I am using ProgressBar ( System.Windows.Forms.ProgressBar in Marquee Mode) as part of this control. I do not need to update the status of the progress bar, I want the chart to be made, so long as it moves forward.

I am currently using it in the following scheme:
- Waiting times ( progress bar appears and starts running)

Charting methods Call - When the chart is ready, the waiting bar will be hidden.

The problem is: Some charting methods are actually computational demands and in such moments, the wait times are free. How can I avoid these freeze? Should I use some sort of threading / background worker? And if so, what is the easiest way to do this?

Note that while the chart is ready I do not need to change the status of the progress bar. I just need the waiting bar, move during all the computations and then close

edit

OK, as suggested, I have created a separate thread for computation of these demands to avoid freezing.

But how to wait and do not freeze the GUI?

I tried, as suggested, something like this:

  threads t = new thread ((=) = & gt; {DoSomeLongAndDemandingTask (with parameter); }); T.Start (); T.Join () // something that should be done after thread ends InvokeMeAfterThreadFinished ();  

But does it freeze the GUI? Is there any other way to avoid these freeze?

You have answered your question - usually the answer is to move the calculation on the background thread A WinForms component named Background Worker, loads a lot of weight for you:

Note that you will not be able to access UI components from the background thread, you can access the UI control To get, the Control.Invoke is required on the UI thread to get a lot (more about it Talked about), Googling for Google will be easy.

Alternatively, sometimes the background thread is ineffective (not sure why), so that you can use the application. DoEvents () - If the memory works, So this message gives the message queue (messages, with control painting, when updating the UI), pending messages. If you only do some work which causes flicker, it can be a quick and easy option - although it is not often advised.


Comments