title: Blocking Methods within Task
body: <p>I'm currently developing a small server application and getting to grips with Task&lt;>, and other associated operations.</p>
  
  <p>I'm wondering how Blocking operations work within a Task.</p>
  
  <p>So for example, I currently use several Libraries with "blocking" operations. One of them is Npgsql (PostgreSQL provider.)</p>
  
  <p>If I do the following...</p>
  
  <pre><code>Task myTask = new Task&lt;&gt;( () =&gt; 
      {
        using(var db = new PostgresqlDatabaseConnection())
        {
               db.ExecuteQuery("SELECT takes 50 ms to get data...")
               db.Insert(anObject); etc....
        }
  
     }
  ).Start();
  </code></pre>
  
  <p>And say, chain it to a bunch of other tasks that process that data. </p>
  
  <p><strong>Is this Efficient?</strong> I.E. Let's say that ExexuteQuery calls some kind of Thread.Sleep(1) or somehow blocks the thread, is this going to effect my Task Execution?</p>
  
  <p>I'm asking because my server uses several libraries that would have to be rewritten to accomodate a totally Asynchronous methodology. <em>Or is this Async enough?</em></p>
  
  <p>*<em>My Thoughts *</em></p>
  
  <p>I'm really just not sure. </p>
  
  <p>I know that if for example, the db.Executre() just ran a while(true) loop until it got it's data, it would almost certainly be blocking my server. Because a lot of time would be spend processing while(true). Or is Task smart enough to know that it should spend less time on this? Or if internally it is using some waiting mechanism, does the Task library know? Does it know that it should be processing some other task while it waits.</p>