Calling selectFolder() using Thread()

Hi,
I’m getting data (approx 200,000 data points) I have generated from a text file, when the selectFolder method fires the callback and runs my method to process it, the program is of course locked into this course of action until it is finished reading and processing the data. What I would like to be able to do is have a progress bar on screen that would show how far through it is. I know I can’t do this when it is reading the data as it is never in the draw loop, so that is why I’m after a threaded solution.

I am trying to use map() to get the progress but not being in the draw means nothing is ever updated visually.
Is there a way to call my selectFolder() call (demonstrated below) OR the callback method processFolderSelected in their own thread?
and yes, I am aware that selectFolder() is called in it’s own thread.

What I am currently doing:

selectFolder("Select a folder to process:", "processFolderSelected");

What I am trying to do (the idea, not this actual code):

thread("selectFolder("Select a folder to process:", "processFolderSelected")");

What I tried:

thread("selectFolder("Select a folder to process:", "processFolderSelected")");

thread(\"selectFolder(\"Select a folder to process:\", \"processFolderSelected\")");

selectFolder("Select a folder to process:", thread("processFolderSelected"));

Method PApplet::thread() requests a String w/ just a method name, nothing more: :no_good_man:
Processing.org/reference/thread_.html

So instead of this totally invalid String syntax argument: :no_entry_sign:
thread("selectFolder("Select a folder to process:", "processFolderSelected")");

You can make a function which invokes PApplet::selectFolder(). Then use thread() to invoke it! :bulb:

Inside that function, you can draw your progress bar over a separate PGraphics, which is then concurrently displayed inside sketch’s draw(). :genie:

1 Like

There is no need to execute selectFolder(...) inside another thread because Processing V3 executes this method in separate thread anyway.

Effectively you would be creating a thread which would create another thread when it executes selectFolder(...)

1 Like

Sorry I missed that!

Once your program has detected that a folder has been THEN create a thread to read the data. In other words seperate the tasks of selecting the folder and reading the data

You can read the data into one of Java 8’s concurrent collections to avoid concurrent data access problems.

Brilliant, I knew it had to be something simple I was overlooking.
Thanks so much.

1 Like