Is it possible in .NET, using C#, to achieve event based asynchronous pattern without multithreading? -


I'm surprised by the architectural design and was thinking that C # is capable of such a design:

Asynchronous, event based / event loop, non-blocking without multithreading.

I think all implementing the standard asynchronous programming model BeginXyz Functions have run a callback on the thread pool thread, which automatically creates multi-threaded applications.

However, you can achieve a single-threaded asynchronous programming model by synchronizing all the functions through a single GUI thread, which can be found in the Control.Invoke or more commonly the SynchronizationContext .

BeginXyz every call must be rewritten with these lines:

  // Start the asynchronous operation (1) var original contents = Synchronize izationContext.Current; Obj.BeginFoo (ar = & gt; // Switch to original thread original contact.post (Ignored = & gt; {var res = obj.EndFoo (); // Continue here (2)}))); Will continue to run on the same thread as code in code (1) marked as  

(2), so that you will only use the thread-pool thread to forward the postback Original (Single) Thread

As a side-note, it is more directly supported by the asynchronous workflow in F # and it can be used for a quite elegant style of GUI programming. I do not know node.js , but I think you might be surprised by the F # asynchronous workflow because they are actually asynchronous / event based / ... The style of programming is cool: -)


Comments