Main thread lock up question

My application does a bunch of file copying (running in the main thread).
As soon as it begins the interface locks up. This is expected.

However is there a way to:

  1. write something too a listbox, and
  2. start an indeterminate progress bar

before the interface locks up?
I would just like make sure there is enough time to say “files copying” and get the indeterminate progress bar going. I don’t need to update the user of the progress of the operation.
~
Thanks

The only clean (and safe way) is to work with a timer and thread. But then you can do everything, including updating the progress. It is not too difficult and there are examples in the example folder and it is worth the 1-2 hours learning it!

All other tricks you might find here, might work now, but sooner or later you will have to use the timer / thread combo.

1 Like

Thank you!
Yes, I am familiar with that method – I use it in several other applications.
It doesn’t, however, seem to work with Mac OS file copying (where I am copying directories with many items).

1 Like

do you put this copying thread to sleep in your copying “loop”? Or can you create some how bundles of files. For instance copy subdirectories one by one in your loop and in-between you are putting your thread to sleep for a few milliseconds?

edit/disclaimer: if have never done this for files. If I had such a need, it was for internal stuff, where I just didn’t care if the interface is frozen. But as I am sure others have done that already.

File operations, even threaded, block the UI. Copying a bunch of files will lock up your app unless you use MBS or declares to use other file APIs to do the work.

1 Like

Thanks @Tim_Parnell, that’s what I’ve been lead to understand.
Is there a way to reliably “pause” the thread just enough to allow the updating of the indeterminate progress bar and add a row to a listbox (or update a text field) prior to the copy beginning?
~
Thanks

hah, so I was right being lazy for my internal projects :wink: … but splitting the files to be be copied into bundles and copying each bundle would work, right? Obviously not helpful if each bundle is 44 GB large.

But the PO said:

I would just like make sure there is enough time to say “files copying” and get the indeterminate progress bar going. I don’t need to update the user of the progress of the operation.

This should still be possible via a timer. Pseudo Code:

  • Timer running permanently, once a flag is set (writeCopyingStarted = true) then update the UI and after that set a second variable (startCopyingProcess to true).
  • In the same timer only kick off the copying when startCopyingProcess is true …

In the thread near the loop boundary put me.Sleep(50) to force a context switch long enough for that to happen. I use this technique in Plugins Pro.

1 Like

Another way to do this is to use an asynchronous Shell to do the actual copying. Or Workers.

1 Like