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.

Why does TaskCanceledException occur?

I have the following test code: void Button_Click(object sender, RoutedEventArgs e) { var source = new CancellationTokenSource(); var tsk1 = new …

c# task-parallel-library c#-5.0
What does MaxDegreeOfParallelism do?

I am using Parallel.ForEach and I am doing some database updates, now without setting MaxDegreeOfParallelism , a dual core processor …

c# .net-4.0 task-parallel-library parallel-extensions parallel.foreach
How to create a task (TPL) running a STA thread?

Using Thread is pretty straightforward Thread thread = new Thread(MethodWhichRequiresSTA); thread.SetApartmentState(ApartmentState.STA); How to accomplish the same using …

c# wpf multithreading thread-safety task-parallel-library
Difference between await and ContinueWith

Can someone explain if await and ContinueWith are synonymous or not in the following example. I'm trying to use TPL …

c# task-parallel-library task async-await
An async/await example that causes a deadlock

I came across some best practices for asynchronous programming using c#'s async/await keywords (I'm new to c# 5.0). One …

c# task-parallel-library deadlock async-await c#-5.0
Why does this async action hang?

I have a multi-tier .Net 4.5 application calling a method using C#'s new async and await keywords that just hangs …

c# asynchronous task-parallel-library async-await c#-5.0
Cancellation token in Task constructor: why?

Certain System.Threading.Tasks.Task constructors take a CancellationToken as a parameter: CancellationTokenSource source = new CancellationTokenSource(); Task t = new Task (/* …

c# .net-4.0 task-parallel-library cancellation-token
Calling async methods from non-async code

I'm in the process of updating a library that has an API surface that was built in .NET 3.5. As a …

c# asp.net multithreading asynchronous task-parallel-library
Using CancellationToken for timeout in Task.Run does not work

OK, my questions is really simple. Why this code does not throw TaskCancelledException? static void Main() { var v = Task.Run(() =&…

c# .net task-parallel-library cancellationtokensource cancellation-token