- Home /
How to execute async method in batchmode correctly?,Questions about how to execute async method in batchmode
I have a static method named DoIt , in this method it will call another method named Process, which will process file data asynchronously.
static void DoIt()
{
...do something
Process(data);
...do something
}
I start unity with following command.
%UNITY_EXE_PATH% -nographics -batchmode -quit -projectPath %LIP_SYNC_PROJECT_DIR% -executeMethod AutoCreateClip.DoIt audiodir %UNITY_PROJECT_AUDIO_DIR% filename in.wav audioduration %AUDIO_DURATION%
It worked fine, since it started unity and execute DoIt method, however, after DoIt finished, unity exit and the Process method does not finish, the data only process half. What may cause this happened?
Answer by Bunny83 · Jul 26, 2019 at 12:25 AM
Unity does not manage your own threads. If you start threads in the background it's up to you to make sure they are finished. From Unity's perspective once the method it should run has finished it's done and will terminate. Note that this is absolute normal behaviour even with other applications. When the main thread finishes the application will terminate unless you actually have code at the end that waits for your background thread. Calling Thread.Join on the main thread will block the main thread until that thread has finished. Since we don't know what you actually do inside your Process method we can't help you any further.