Running scripts in the background

Normally, when you run a script in FVC, it runs on the UI thread. This allows you to create your own user interface if needed. FVC will run your script and be paused until it has finished running.

However, if you want to run a longer script you can run part of the script in a worker thread. The FVC scripts are started with async support so if you run your work in a worker thread and await correctly, FVC will be responsive when your script is running. Be aware though that what the user does in the user interface might interfere with your script, the user could for example remove a video or change selection.

At the top of your script, we need to bring in the C# task library:

using System.Threading.Tasks;


Then to run a function in your script, you write this:

await Task.Run(()=> MyFunction());

Task.Run(…) will start a task, and MyFunction will run in the task. The await causes the script to wait until the task has finished running MyFunction().