I've tried a few different Unity multiple thread plugins and haven't had great experiences. I'm not saying "UnityMainThreadDispatcher" can't be a good solution, but it seems like running Unity specific functionality on multiple threads would be a smoother, better documented process if the Unity team tackled it. Also, it's good to avoid including extra plugins if you can help it. That said:
Depending on the contents of your one "function that I need to call from the main thread", you could slice up your code into more modular pieces and make that main thread call in between firing async tasks. For example, I have a process heavy task that requires a loading bar for the user. I create a global variable that an await Task.Run()
builds on, then I make updates/retrieve data from the Unity API on the main thread (including updating the progress bar), and then I go into the next await Task.Run()
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…