Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

task based sequence manager in c# for Unity3D

Note:this question should have been written on https://gamedev.stackexchange.com/ since it refers to Unity3D development (nothing to do with c# Unity Framework)

I need a simple (single thread) library that allows to run sequences of asynchronous tasks that could last over the time (usually using yield).

in actionscript I used to use http://www.dpdk.nl/opensource/running-tasks-in-order-with-a-task-based-sequence-manager which was a great task sequencer.

Is there something similar in c#?

N.B.: while the system.threading.task class seemed a good solution initially, Unity 3.5 does not support .net framework 4. The version I can use is 3.5. Are there alternatives?

like image 794
sebas Avatar asked Dec 14 '25 15:12

sebas


1 Answers

You want to take a look at the Task Parallel Library. This library can be used for multi-threading or not, so it is fairly robust. In fact, it is what the next version of .NET's async/await keywords are built on. I will write a quick code snippet shortly.

var task = Task.Factory.StartNew<String>(
               ()=>
               {
                   //Do some long running task
                   return "Here are my results from part 1";
               })
           .ContinueWith<Int32>(
               (previousTask)=>
               {
                   var previousResult = previousTask.Result;
                   //Do some other long running task using the previous result
                   return 1;
               }); 

There is A LOT that you can do with the TPL. This is just a general idea.

Also, there is the yield keyword for iterators, but that is not necessarily asynchronous.

like image 119
Justin Pihony Avatar answered Dec 16 '25 04:12

Justin Pihony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!