- Home /
Can't include System.Threading.Tasks
I'm trying to do asynchronous web calls outside of the www class using httpwebrequest. At the end of my asynchronous web requests, I need to tell unity to do stuff with the data, but unity doesn't like it because I'm calling from off the main thread. My intention was to create a TaskScheduler on the main thread, tell the web request about it, and have the web request schedule it's tasks on the main thread when it completes. But intellisense doesn't recognize System.Threading.Tasks (it does recognize System.Threading), and therefore I get compile errors if I try to create a TaskScheduler.
Open to solutions to instantiate a Task Scheduler, or alternatives for getting back to the main thread once I'm off it.
Answer by Kitty001 · Oct 02, 2017 at 10:37 PM
I just had to solve this. Now threading.Tasks are included in Unity 2017. Download the latest Unity, 2017, go to Edit/ Project Settings/ Player > scroll down and select to 'Configuration and set Run Time API as "Experimental (.Net 4.6 Equivalent)."
I'm running Unity 2017.2 and have the runtime set to the experimental .Net 4.6 like you mentioned. $$anonymous$$y build target is set to Universal Windows Platform. Unity won't recognize System.Threading.Tasks. It finds System.Threading, but not the Tasks namespace. Consequently, calling Task.Run() results in the red squiggly. Any tips?
Answer by hexagonius · Feb 20, 2015 at 04:18 PM
Maybe this helps, just found it for a similar question:
http://answers.unity3d.com/questions/357033/unity3d-and-c-coroutines-vs-threading.html
Answer by youblistermypaint · Jun 09, 2016 at 02:50 PM
It's because Unity is stuck on a older version of Mono, 3.5 I believe. Tasks were introduced in 4.
It may be possible to use the backported version of the Tasks library in Unity. I can't personally vouch for this approach as I haven't tried it myself.
It's on $$anonymous$$ono 5.9 now, if the OP can upgrade without issues...
Edit: Unless it's still .NET 3.5?
Is it? 5.3 is not, is the 5.4 beta on it? I don't see it on the roadmap.
$$anonymous$$onoDevelop and the underlying $$anonymous$$ono .NET implementation are two different things.
Yeah, i realized when I thought bout how 5.9 seemed too high. :/