Jump to content

ProgressBar Multithreading Demo


Recommended Posts

This comes up kind of often.


The progress bar in Unigui doesn't behave like you are used to in Delphi, because of the fact that the server and client actually runs asynchronously.


So, in order to get the result you expect you are pretty much forced to implement a multithreaded solution. I think it is well worth noting here, that this is actually the Correct way to use the progress bar even in standard VCL applications as well and not doing it this way and perhaps using tricks like Application.ProcessMessages is inherently evil.


The attached project shows a very basic example of a multithreaded application which uses a worker thread to do a task that takes a while to complete (it calls sleep one hundred times). Every time the thread returns from sleep it checks for termination from the UI, updates the progress count and goes back to sleep. When the progress count has reached 100 the thread terminates automatically.


The UI inspects the progress of the worker thread at regular intervals using TUniTimer. It then updates the progress bar and returns control to the user. The user can request that the thread terminates by clicking a cancel button.


  • Upvote 6
Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...