Progress information during File IO

My app reads data from a file with TextInputStream. I would like to show the user some logging in a canvas. This is not working, I assume because File IO prevents thread switching. I try to give a message with iOSMessageBox before the procedure starts. I get this message when the IO-procedure has been completed.
Is there a way to give the user some Progress-information during the IO?

Is your file so big it takes several seconds to load ?

If you use the method in the LR that employs a tight while/wend loop, the UI won’t update during the loop.

In order to update the UI as you want to do, you must replace the loop by a timer.

Testing with 400 records, putting them in a sqliteDB. I already tried the Timer. No success.
I also have put a delay of 2 seconds in the loop. Same result.
Thanks for your reply.

Just one question: why?

Because the user doesn’t notice for some time if anything is happening. It is not a big deal but it would nice to give some feedback.

[quote=250920:@Herman Dubach]Testing with 400 records, putting them in a sqliteDB. I already tried the Timer. No success.
I also have put a delay of 2 seconds in the loop. Same result.[/quote]

Whatever you do in a loop, including a delay of whatever number of seconds or dozens of them, the UI will not be updated until the end of the loop. You must simply not use a loop at all.

Instead of a loop, place the code in the action event of a timer.

For instance, instead of :

While not inputstream.eof TextArea1.Text = TextArea1.Text + inputstream.ReadLine Wend inputstream.close

Make inputstream a property of the view, and put this in the action event of a multiple timer that you start at the same point you would have started your loop :

If not inputstream.eof TextArea1.Text = TextArea1.Text + inputstream.ReadLine else inputstream.close Me.Mode = Xojo.Core.Timer.Modes.Off end if

As you have not posted your code, this is an example of the principle of what you should do, not the actual code.

Another option might be to read the file in a thread and use a timer on the view (UI/main thread) to update progress?

That works too. Maybe it is easier since the code in the timer does not need much refactoring.

I don’t see any way to update the UI without a timer, though.

I agree. I’ve made that mistake myself. :wink:

Thank you Michel, it works. Also Jason, thanks for your attention.

[quote=251743:@jean-paul devulder]hi herman,
in next update of dtplugins, you can update ui without using timer[/quote]
I had no idea what “dtplugins” are. Google led me to
[b]Dethomsoft
dtPlugins are no longer for sale.

Support for existing customers will continue.[/b]
http://www.dethomsoft.com

Is this something different?

[quote=251743:@jean-paul devulder]hi herman,
in next update of dtplugins, you can update ui without using timer[/quote]

What? dtPlugins still lives @jean-paul devulder ???

Are you going to resume sales, then ?

Oh my. I thought you wanted support requests to go down…

Can’t you use the spinning progress wheel. Made visible before your loop and invisible after. I have just added one to a window and run a tight loop and it keeps on spinning. Just make it visible, call your thread, read your file, kill your thread make it invisible.