Top "Task-parallel-library" questions

The Task Parallel Library is part of the .NET Framework since .NET 4. It is a set of APIs to enable developers to program asynchronous applications.

Use Task.Run() in synchronous method to avoid deadlock waiting on async method?

UPDATE The purpose of this question is to get a simple answer about Task.Run() and deadlocking. I very much …

c# .net asynchronous task-parallel-library async-await
List<T> thread safety

I am using the below code var processed = new List<Guid>(); Parallel.ForEach(items, item => { processed.Add(…

c# list c#-4.0 task-parallel-library parallel-extensions
Should I always use Task.Delay instead of Thread.Sleep?

I have recently seen several recommendations stating that Thread.Sleep should never be used in production code (most recently in …

c# .net async-await task-parallel-library thread-sleep
How does C# 5.0's async-await feature differ from the TPL?

I don't see the different between C#'s (and VB's) new async features, and .NET 4.0's Task Parallel Library. Take, …

c# task-parallel-library c#-5.0 async-await
How to cancel a task that is waiting with a timeout without exceptions being thrown

When canceling a task that has a timeout (before the timeout has ended) using a cancel token an exception is …

c# multithreading c#-4.0 task-parallel-library pfx
what is the correct way to cancel multiple tasks in c#

I have a button thats spawns 4 tasks. The same button changes to a cancel button and clicking this should cancel …

c# c#-4.0 task-parallel-library task pfx
How to get thread Id in C#

public bool HasItemsFromPropertySet(InfoItemPropertySet propertySet, CompositeInfoItem itemRemoved) { var itemAndSubItems = new InfoItemCollection(); if (itemRemoved != null) { itemAndSubItems.Add(itemRemoved); //foreach (InfoItem item …

c# task-parallel-library parallel-extensions
MaxDegreeOfParallelism = Environment.ProcessorCount slows down execution time on my CPU

I have the following program (that I got from http://blogs.msdn.com/b/csharpfaq/archive/2010/06/01/parallel-programming-in-net-framework-4-getting-started.aspx) that …

c# task-parallel-library parallel.foreach
How to process MSMQ messages in parallel

I'm writing a windows service to consume MSMQ messages. The service will have periods of high activity (80k messages coming …

.net-4.0 parallel-processing msmq task-parallel-library
HttpClient in using statement causes Task cancelled

I created a FileResult : IHttpActionResult webapi return type for my api calls. The FileResult downloads a file from another url …

c# asp.net-web-api task-parallel-library httpclient using-statement