Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think that all the <code>BeginXyz</code> operations that implement the standard asynchronous programming model run the callback on a thread pool thread, which makes the application automatically multi-threaded.</p> <p>However, you can achieve single-threaded asynchronous programming model by synchronizing all the operations through the single GUI thread that is maintained for windows applications using <code>Control.Invoke</code> or more generally, <code>SynchronizationContext</code>.</p> <p>Each call to <code>BeginXyz</code> would have to be rewritten along these lines:</p> <pre><code>// Start asynchronous operation here (1) var originalContext = SynchronizationContext.Current; obj.BeginFoo(ar =&gt; // Switch to the original thread originalContext.Post(ignored =&gt; { var res = obj.EndFoo(); // Continue here (2) })); </code></pre> <p>The code marked as (2) will continue running on the same thread as the code in (1), so you'll use the thread-pool thread only for forwarding the postback back to the original (single) thread.</p> <p>As a side-note, this is more directly supported by asynchronous workflows in F# and it can be used for quite elegant style of GUI programming <a href="http://dotnetslackers.com/articles/net/Programming-user-interfaces-using-f-sharp-workflows.aspx" rel="noreferrer">as described here</a>. I don't know <code>node.js</code>, but I suppose that you may be also amazed by F# <em>asynchronous workflows</em> as they are really cool for asynchronous/event based/... style of programming :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload