1

As I understand, when you have an await, the compiler splits your method into two parts, one part before the await and another part after it. The IL will create state machine etc.

The moment await is encountered, the control returns to the main thread; is what I know. As if there were a return keyword. If this is correct/partially correct, then I want to know where is the awaited operation running as the control was returned to main thread. I am not clear about where the awaited operation is running and this is what I'd like to know...

If I have following commands:

code;
code;
await *someLongRunningOperation*; 
moreCode;

I want to know where is the someLongRunningOperation running while we await? Does it get a separate thread from thread pool? Is it running on a separate thread/core??? Not sure... Answers appreciated...

  • 3
    Actually, [it may not be running anywhere](https://blog.stephencleary.com/2013/11/there-is-no-thread.html). – Jeroen Mostert Sep 23 '21 at 11:42
  • 2
    Hugely depends on the `someLongRunningOperation`. – Guru Stron Sep 23 '21 at 11:45
  • 1
    There are multiple ways to implement that. If it's an async method, it will be a statemachine aswel. If the method returns a TaskCompletionSource.Task, something should trigger the SetResult. It might be triggered on an IO action. – Jeroen van Langen Sep 23 '21 at 11:51
  • @JeroenvanLangen I know this comment has nothing to do with the post but I really hugely gargantuanly admire http://vr.vanlangen.biz/ even though I don't have any idea what it is or what it is used for. – Soner from The Ottoman Empire Sep 23 '21 at 13:56
  • 1
    @snr Thanks!, I'm always figgering out new techniques. This page was a trial for WebVR and typescript. I'm currently working at a robotic machine manufacturer and this was a model for dual picking-up crisp-bags with vacuum (a gripper). If you run this on 3d-glasses, you can see it in VR. (i tested it with GearVR) – Jeroen van Langen Sep 23 '21 at 14:11

0 Answers0