How to use progress bar according to the code execution timing.
-
I have created one windows application form, in that form loading i written code and for execution it will take 1 or 2 minutes (lenghty code). This i need to show in progress bar so that user can think process is going. I used progress bar in that form in loading. The progress bar is not showing but code is executing. How to use progress bar according to the code execution timing. Please reply me. Thanks in advance.
-
I have created one windows application form, in that form loading i written code and for execution it will take 1 or 2 minutes (lenghty code). This i need to show in progress bar so that user can think process is going. I used progress bar in that form in loading. The progress bar is not showing but code is executing. How to use progress bar according to the code execution timing. Please reply me. Thanks in advance.
In all probability, you are loading the form and displaying the progress bar using the UI thread. What you need to do is separate out the logic that takes a long time to run into a background thread, and periodically refresh/pulse the progress bar. I would argue though, that you have a poor user design if they have to wait 2 minutes for a form to load. I'd drop kick any developer who released code like that for me.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
I have created one windows application form, in that form loading i written code and for execution it will take 1 or 2 minutes (lenghty code). This i need to show in progress bar so that user can think process is going. I used progress bar in that form in loading. The progress bar is not showing but code is executing. How to use progress bar according to the code execution timing. Please reply me. Thanks in advance.
If you want a snappy GUI and/or you want to show some progress, you should limit the execution time of each of your GUI event handlers to say less than 30 msec. So having lengthy operations in a Form Load handler is no good; you should instead: - launch a thread (possibly a
BackgroundWorker
) in the Form Load handler; - have that thread perform the lengthy operation (e.g. database access) and store results in some data structure; - then use Invoke to have the GUI thread update the GUI, showing the newly acquired data, and probably enabling the Controls that now should be functional. When the operation that needs to show progress is indivisible, you can't really show progress, all you can indicate is that time is progressing, so you should estimate a worst-case time span, and show a progress bar that advances at periodic points in time. ASystem.Windows.Forms.Timer
is excellent for such purpose. :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
You just had to type "Progress bar C#" into Google search box instead of typing so much here. Check the search result - progress bar c#[^]
..Go Green..
Actually, it's a good job the user did. What they were displaying is a classic case of attempting to run multiple things on the UI thread. Had they just asked how to show the progress bar, they might not appreciate the difficulties in what they were trying to accomplish.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Actually, it's a good job the user did. What they were displaying is a classic case of attempting to run multiple things on the UI thread. Had they just asked how to show the progress bar, they might not appreciate the difficulties in what they were trying to accomplish.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
I am sorry I missed the main issue in the question. I checked your and Luc's reply below. How do I implement a progress bar in C#?[^] - this is from the very first page of the search link and if I understood your answer correctly, this is what you were talking about below. All I meant to say that the OP should have done a little research before asking.
..Go Green..
-
In all probability, you are loading the form and displaying the progress bar using the UI thread. What you need to do is separate out the logic that takes a long time to run into a background thread, and periodically refresh/pulse the progress bar. I would argue though, that you have a poor user design if they have to wait 2 minutes for a form to load. I'd drop kick any developer who released code like that for me.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
I take it you've never run Calibre[^]. Takes for_ever_ to load. Have no idea what it's doing, other than not starting promptly. :laugh:
There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.
GenJerDan wrote:
Have no idea what it's doing
Thread.Sleep(30000000);
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
GenJerDan wrote:
Have no idea what it's doing
Thread.Sleep(30000000);
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
I have created one windows application form, in that form loading i written code and for execution it will take 1 or 2 minutes (lenghty code). This i need to show in progress bar so that user can think process is going. I used progress bar in that form in loading. The progress bar is not showing but code is executing. How to use progress bar according to the code execution timing. Please reply me. Thanks in advance.
-
I have created one windows application form, in that form loading i written code and for execution it will take 1 or 2 minutes (lenghty code). This i need to show in progress bar so that user can think process is going. I used progress bar in that form in loading. The progress bar is not showing but code is executing. How to use progress bar according to the code execution timing. Please reply me. Thanks in advance.
hi sr159 Sometimes there's no practicable way to measure progress towards completion, using a simple mathematical formula. In such cases, you need to estimate in advance how long the operation will take and then change the ProgressBar in accordance with the percentage time elapsed since inception. You also need to avoid moving the progress bar up to 100% until the overall task has completed. take a look there[^]