1

I'm relatively new to c# (not to programming in general), and I cant seem to find an answer to this question that is just plain and simple.

are coroutines asynchronous? (y/n/both/abort)

Fonix
  • 11,447
  • 3
  • 45
  • 74
  • for extra clarity: does the coroutine run on the same thread that the main runloop of a program runs on? or is it on a completely different thread? – Fonix May 24 '14 at 14:20
  • 2
    C# does not have the notion of coroutine. It is a specific Unity terminology, it is just an iterator that uses the C# *yield* keyword. No, they are not asynchronous, they are state machines. Every time you call it, synchronously, it does something else. – Hans Passant May 24 '14 at 14:25
  • 1
    i see, thanks for clearing that up. thought this was a standard c# feature, bit hard to tell when learning both c# and unity together. – Fonix May 24 '14 at 14:27
  • 1
    If this is about unity3d the tag is wrong... – rene May 24 '14 at 14:53
  • My take on [async coroutines with C# 8.0](https://stackoverflow.com/a/62687410/1768303) using `IAsyncEnumerable`, `IAsyncEnumerator`, `await foreach` etc. – noseratio Jul 03 '20 at 00:27

1 Answers1

1

You should read Eduasync part 13: first look at coroutines with async. Coroutines are not asyncronous by standard, but using the await and async (C# 5.0 and .NET 4.5) keyword you can make them to.

Jevgeni Geurtsen
  • 3,133
  • 4
  • 17
  • 35
  • 2
    In the context of Unity, [coroutines seem to refer to iterator methods](http://docs.unity3d.com/Documentation/Manual/Coroutines.html). –  May 24 '14 at 14:24