Questions tagged [task-parallel-library]

The Task Parallel Library is part of the .NET Framework since .NET 4. It is a set of APIs that simplifies the process of adding parallelism and concurrency to applications.

The Task Parallel Library (TPL) is a set of public types and APIs in the System.Threading and and the System.Threading.Tasks namespaces in the .NET Framework 4 and up. The purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications. The TPL scales the degree of concurrency dynamically to most efficiently use all the processors that are available. In addition, the TPL handles the partitioning of the work, the scheduling of threads on the ThreadPool, cancellation support, state management, and other low-level details.

Related Tags

Free resources

6189 questions
4
votes
2 answers

Update the WPF UI while processing - best use of async await

Here is what i have tried - It works, as far as seeing the UI refreshed, but i don't think it's the best use of async / await. How can i improve on this? private async void btnQuickTest_Click(object sender, RoutedEventArgs e) { XmlReader…
joedotnot
  • 4,810
  • 8
  • 59
  • 91
4
votes
1 answer

Concurrency without multithreading Async/Await

There is a strong emphasis that async/await is unrelated to multi-threading in most tutorials; that a single thread can dispatch multiple I/O operations and then handle the results as they complete without creating new threads. The concept makes…
4
votes
1 answer

Throughput of TPL dataflow pipeline

We have a TPL dataflow pipeline with following blocks: Transform Block A: Http post call Transform Block B: Database IO Transform Block C: Some unit conversion data (basically CPU intensive task) Transform Block D: Publish to Google…
Savaratkar
  • 1,974
  • 1
  • 24
  • 44
4
votes
1 answer

How to handle task cancellation using ContinueWith?

I've got the following example: public void Run() { var ctc = new CancellationTokenSource(); try { DoAsync(ctc).Wait(); Console.WriteLine("Done"); } catch (AggregateException exception) { …
4
votes
2 answers

Equivalent of Array in Concurrent Collections

I have the following process in a Single Thread Environment: int[] ages = { 40, 30, 18, 23, 60, 24 }; for (int i = 0; i < ages.Length; i++) { if (ages[i] < 21) ages[i] = 0; } As an example, but now I want to do this process in a Multi Thread…
Josbel Luna
  • 2,574
  • 3
  • 17
  • 25
4
votes
2 answers

Does any one know how to use IOCompletionPortTaskScheduler and IOTaskScheduler in ParallelExtensionExtras and what are their use?

Does any one know how to use the following classes in ParallelExtensionExtras and what they are used for? IOCompletionPortTaskScheduler.cs IOTaskScheduler.cs
Abdul Khaliq
  • 2,423
  • 12
  • 40
  • 65
4
votes
1 answer

Why is Task.WhenAny so slow when called many times against the same TaskCompletionSource?

If a class has a member TaskCompletionSource m_tcs with a long lifetime, and if Task.WhenAny is called with m_tcs.Task as one of its arguments, performance seems to degrade exponentially when the number of calls surpasses 50,000 calls or…
Mike Henry
  • 2,401
  • 1
  • 25
  • 34
4
votes
1 answer

How to get a Synchronization Context for the second form shown

[EDIT] Rephrased and Simplified whole post [/EDIT] In this blog, the following (I simplified it a bit) is given as an example of using a SynchronizationContext object to run a Task on the UI thread: Task.Factory.StartNew(() =>"Hello…
Chris Pfohl
  • 18,220
  • 9
  • 68
  • 111
4
votes
1 answer

Task and Task in Func delegate

I want to cleanup some of my code. I have overloaded method. Can I somehow simplyfy this code and invoke one method in another ? Cant figure out how to do this. private async Task DecorateWithWaitScreen(Func> action) { …
TjDillashaw
  • 787
  • 1
  • 12
  • 29
4
votes
2 answers

Consuming BlockingCollection with multiple consumers

I have a program as follows class Program { public static int TaskCount { get; set; } public static BlockingCollection queue = new BlockingCollection(new ConcurrentQueue()); static void…
ibubi
  • 2,469
  • 3
  • 29
  • 50
4
votes
1 answer

is there an idiomatic way to route elements which fail in a TransformBlock within a TPL dataflow graph?

I am using TPL dataflow to create a bufferBlock of input elements which are processed by a TransformBlock that outputs to an output bufferBlock inputQueue = new BufferBlock; processQueue = new TransformBlock
compound eye
  • 1,898
  • 18
  • 23
4
votes
2 answers

Handling WF 4.0 long running activity using TPL

I created an activity which executes a web request and stores the result into the database. Usually this process takes about 1 hour and it makes workflow engine to behave abnormally. I found out that for these long running activities I should write…
4
votes
1 answer

Control does not come back to the awaited webClient after calling Async WebAPI

We have a Restful Client-Sever environment and I am trying to debug my code where client code looks like following: await Client.DoWork(Id); While server code looks like following: public virtual async Task DoWork(long Id) { …
Lost
  • 12,007
  • 32
  • 121
  • 193
4
votes
1 answer

Why does Task.Wait() not behave as expected with Console.WriteLine() - .NET Core?

I am trying to understand the basics of async programming a bit better, so I have created the following snippet: private void TaskContinuations() { // Task for counting prime numbers Task primeNumberTask = Task.Run(() => …
Anytoe
  • 1,605
  • 1
  • 20
  • 26
4
votes
2 answers

Task.WhenAny - A Task was Cancelled

In the following code: if (await Task.WhenAny(task, Task.Delay(100)) == task) { success = true; } else { details += "Timed out on SendGrid."; await task.ContinueWith(s => { …
SB2055
  • 12,272
  • 32
  • 97
  • 202