Will creating a new task generate a background thread or a thread pool thread

asp.net, async-await, c#, multithreading

Solution

Yes, using the `Task` constructor executes the code in another thread, in this case a thread pool thread.

You should be using a DB operation that is inherently asynchronous, not synchronous. You should not be using the `Task` constructor at all to construct a `Task` that represents an asynchronous operation. How you go about doing this will depend on what API you're using to perform your IO.

Problem

I'm trying to make a database call async for an ASP.NET application. If I understand things correctly, I do not want to utilize thread pool threads for async I/O calls so I can keep the thread pool processing requests. Will the code below chew up a thread from my thread pool or generate a background thread? ``` public IEnumerable<dynamic> DbCall(string sql) { return // DB Operation; } public Task<IEnumerable<dynamic>> DbCallAsync(string sql) { var task = new Task<IEnumerable<dynamic>>(() => this.DbCall(sql)); task.Start(); return task; } ```

Original source