# Progress bar update during sort

**URL:** <https://forum.xojo.com/t/progress-bar-update-during-sort/36331>\
**Category:** Windows\
**Created:** [February 26, 2017, 12:55am UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331 "2017-02-26T00:55:19Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [February 27, 2017, 3:17am UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/21 "2017-02-27T03:17:39Z")

</div>

Since the words don’t change, can you just store a pre-sorted file?

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [February 27, 2017, 3:58am UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/22 "2017-02-27T03:58:21Z")

</div>

> [@318107:@Mark Jordan](#):
>
> Is it unreasonable for a sort to take 6 seconds?

Not at all. As you have found, the built-in sort function doesn’t yield time back to the system, so you either have to write your own sort routine that does yield, or even better

> [@318112:@Kem Tekinay](#):
>
> can you just store a pre-sorted file?

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [February 27, 2017, 4:03am UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/23 "2017-02-27T04:03:57Z")

</div>

I ran a test here. I loaded the text, split it, removed all the non-word characters, then sorted it. The whole operation took a little over a second.

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [February 27, 2017, 4:08am UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/24 "2017-02-27T04:08:44Z")

</div>

Also, if you’re looking to count the occurrences of each word, you don’t need to sort for that. I used a Dictionary and that operation took about 3 seconds. Since that’s a loop, it will work well with either a Progress Bar or in a Thread.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [February 27, 2017, 8:05am UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/25 "2017-02-27T08:05:21Z")

</div>

[quote=318108:@Mark Jordan]Hm. Doesn’t work. I put a break immediately after turning the timer on and it breaked (broke?) there … but only after the thread had completed its work. IOW, the thread was a tight loop that wouldn’t let go of itself.

I did follow your instructions to the letter. So I’m not sure what’s the issue.[/quote]

“Does not work” is not a programming term. Can you elaborate ? What happens ?

A tight loop in a thread should not prevent the main thread from running. I tried it long ago.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [February 27, 2017, 9:44am UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/26 "2017-02-27T09:44:13Z")

</div>

OK. I just tried on a test project. A tight loop indeed does not freeze the UI if it is in a thread, but sort does. It probably takes place on the main thread no matter what.

The helper appears to be the best option. Since it will run on a different processor core, it cannot be stopped by the sort operation.

---

<div class="post-metadata">

**Author:** ![Mark\_Jordan](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/c6cbf5/32.png) [@Mark\_Jordan](https://forum.xojo.com/u/Mark_Jordan)\
**Post date:** [February 27, 2017, 5:14pm UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/27 "2017-02-27T17:14:39Z")

</div>

> [@318112:@Kem Tekinay](#):
>
> Since the words don’t change, can you just store a pre-sorted file?

It’s a method to count word frequencies. I’m using it mainly for Bible frequencies – the whole Bible text or by books of the Bible – but it also can be used for any text file. Storing it really wouldn’t make any difference as far as I can see.

The sort makes it easy to count the occurrences of each word. I suppose I could write my own sort or an alternative method but not sure I want to do that at this point. It works, it just freezes for about 6 seconds. It’s not terrible, just an annoyance.

---

<div class="post-metadata">

**Author:** ![Mark\_Jordan](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/c6cbf5/32.png) [@Mark\_Jordan](https://forum.xojo.com/u/Mark_Jordan)\
**Post date:** [February 27, 2017, 5:16pm UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/28 "2017-02-27T17:16:54Z")

</div>

[quote=318130:@Michel Bujardet]OK. I just tried on a test project. A tight loop indeed does not freeze the UI if it is in a thread, but sort does. It probably takes place on the main thread no matter what.

The helper appears to be the best option. Since it will run on a different processor core, it cannot be stopped by the sort operation.[/quote]

Thanks for the effort. “Does not work” simply meant the thread didn’t alleviate the problem of a non-responsive progress bar. There are a couple other options here I might try. Since I’m just creating word frequencies, there might be a faster way.

Thanks again for the help.

---

<div class="post-metadata">

**Author:** ![Mark\_Jordan](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/c6cbf5/32.png) [@Mark\_Jordan](https://forum.xojo.com/u/Mark_Jordan)\
**Post date:** [February 27, 2017, 5:17pm UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/29 "2017-02-27T17:17:37Z")

</div>

> [@318119:@Kem Tekinay](#):
>
> Also, if you’re looking to count the occurrences of each word, you don’t need to sort for that. I used a Dictionary and that operation took about 3 seconds. Since that’s a loop, it will work well with either a Progress Bar or in a Thread.

I haven’t used Dictionaries up to this point. Maybe it’s time I explored. Thanks for the help.

---

<div class="post-metadata">

**Author:** ![Mark\_Jordan](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/c6cbf5/32.png) [@Mark\_Jordan](https://forum.xojo.com/u/Mark_Jordan)\
**Post date:** [February 27, 2017, 5:18pm UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/30 "2017-02-27T17:18:25Z")

</div>

> [@318118:@Kem Tekinay](#):
>
> I ran a test here. I loaded the text, split it, removed all the non-word characters, then sorted it. The whole operation took a little over a second.

Did you do this with a file as large as the entire Bible? I can’t come close to that speed.

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [February 27, 2017, 5:29pm UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/31 "2017-02-27T17:29:39Z")

</div>

Yes, I found and used the King James version.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [February 27, 2017, 6:26pm UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/32 "2017-02-27T18:26:40Z")

</div>

> [@318199:@Mark Jordan](#):
>
> Thanks for the effort. “Does not work” simply meant the thread didn’t alleviate the problem of a non-responsive progress bar.

Indee, I verified it. You best option if you want to display a progressBar is the helper one.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:40pm UTC](https://forum.xojo.com/t/progress-bar-update-during-sort/36331/33 "2020-10-29T18:40:26Z")

</div>



[Previous page](https://forum.xojo.com/t/progress-bar-update-during-sort/36331.md?page=1)
