How to do async operation on appliation quit ?

Hi, i need to send data using async HttpWebRequest when application quit. Send operation perfermed in another thread.
Is it possible to keep alive thread when unity close main precess ? Or it’s wrong way to do this ?
So is there another way to do some async actions when application close ?

This highly depends on the platform. Since you can’t really stop Unity from exiting when it’s closed your only way is to suspend / block the main thread and do your sending on a seperate background thread.

However on iOS or Android there’s no way with Unity’s build-in methods as the user could choose to simply wipe an app from RAM. The best bet on those platforms would probably be some kind of native activity / service which runs in the background.

The same should hold true for WebGL builds. If the user closes the tab or the browser a webpage usually can’t prevent that from happening. So there’s no guarantee that a webrequest will complete before it’s shutdown

Keep in mind that if you block the main thread in standalone builds you should use a reasonable timeout. Always keep in mind that it’s possible that the user (currently?) doesn’t have a network connection. Also note that a user can of course kill an application on windows with the taskmanager, In this case you also don’t have a chance to send out a web request.