nyolc8 215 Posted January 16, 2015 Hello all, I'm asking if asynchronous tasks are possible in GTA4 scripthook? Is it supported? Share this post Link to post Share on other sites
nyolc8 215 Posted January 18, 2015 Is there a trick or way to run multiple tasks somehow? The methods I tried just made my game hang when the asynchronous method got started (screen frozen into a static image, sound stopped). Share this post Link to post Share on other sites
InfamousSabre 224 Posted January 19, 2015 Certain things you can't do asynchronously as they (as you've noticed) make the game hang. I'm using ScriptHook .Net and I try to avoid anything involving GTA.Script, GTA.Game, GTA.World, or GTA.Native Classes. Usually fairly easy to work around, however. Haven't had any issues using anything in GTA.Ped or GTA.Vehicle classes, but GTA.Script.Exists() and GTA.Game.Exists() make the game hang, of course, so you'll have to check for existence some other way. Share this post Link to post Share on other sites
byteMe420 64 Posted January 23, 2015 whatever you need to do with GTA you do in your script, anything else can run in another thread which can set flags that tell your script what to do... you can muti thread just have to use threads to tell your script what to do... as long as you dont use waits in your script then it can respond accordingly in a tick Share this post Link to post Share on other sites
nyolc8 215 Posted January 29, 2015 I tried making multithread in c# (VS 2013 community edition) but it just doesn't work. Can you show an example for this? Because I read multiple solutions and commands to achive this but none of them worked for me. Share this post Link to post Share on other sites
Jitnaught 370 Posted January 29, 2015 I tried making multithread in c# (VS 2013 community edition) but it just doesn't work. Can you show an example for this? Because I read multiple solutions and commands to achive this but none of them worked for me. System.Threading.Thread thread = new System.Threading.Thread(() => { }); thread.IsBackground = true; thread.Start(); ? Share this post Link to post Share on other sites
nyolc8 215 Posted January 29, 2015 Thanks, I didn't tried this, I'll look into it Share this post Link to post Share on other sites
nyolc8 215 Posted January 31, 2015 (edited) System.Threading.Thread thread = new System.Threading.Thread(() => { }); thread.IsBackground = true; thread.Start(); So I tried this, and got an "error in script" message, then the script stopped for a few seconds (I think while the wait() command paused it), then the game got hang. Can I use "Wait(XX);" in the new thread? (that would be the whole point for me in this multithreading question) edit: yes, the game hangs after the wait command, and when it should continue. edit2: used "Thread.Sleep();" instead of "Wait();" and looks like it works nicely. Edited January 31, 2015 by nyolc8 Share this post Link to post Share on other sites
Jitnaught 370 Posted January 31, 2015 Yeah you have to use Thread.Sleep Share this post Link to post Share on other sites
formel117 4 Posted February 21, 2015 You can also use Tasks, https://msdn.microsoft.com/en-us/library/system.threading.tasks.task%28v=vs.110%29.aspx. I've used them multiple times, mostly for HTTP GET/POST in the backgrounds, but they also work with the ScriptHook.NET functions. Share this post Link to post Share on other sites