Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I also have read that one should not start long-running code on the threadpool threads</p> </blockquote> <p>The thread pool <em>will</em> respond to long-running code correctly, so it's not like you <em>can't</em> do it - it's just not the <em>most efficient</em> way to do it.</p> <p>Also note that <code>Task.Delay</code> implies the <em>opposite</em> of "long-running" - the individual <code>Task</code> actually completes at the point of the <code>await</code> and is no longer on the thread pool. Another <code>Task</code> is created and queued to the thread pool when <code>Task.Delay</code> completes. The <code>Task</code> returned by <code>Task.Run</code> (when you pass it an <code>async</code> delegate) is actually a "proxy <code>Task</code>" that represents the entire delegate.</p> <blockquote> <p>is it possible to still use all the C# async language features (such as Task, 'await', 'async') on "regular" threads and not use the threadpool?</p> </blockquote> <p>In your situation, you don't need it, but it <em>is</em> possible. My <a href="http://nitoasyncex.codeplex.com/" rel="nofollow">AsyncEx library</a> includes an <code>AsyncContextThread</code> type that exposes a <code>TaskFactory</code> property you can use to start <code>Task</code>s on that thread.</p> <blockquote> <p>I'm servicing all instances "in parallel" using Task.Run()</p> </blockquote> <p>In your case, you don't need <code>Task.Run</code> or a <code>TaskFactory</code> at all. You can easily do this in parallel without explicitly sending work off to the thread pool:</p> <pre><code>string[] instanceNames = ...; var tasks = instanceNames.Select(ServiceInstanceAsync); await Task.WhenAll(tasks); private static async Task ServiceInstanceAsync(string name) { await DownloadAndProcessFileAsync(); await Task.Delay(15000); await ExecuteSSHAsync(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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