Progress bar update during sort

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

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

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.

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.

[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.

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.

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.

[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.

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

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

Yes, I found and used the King James version.

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