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
3 answers

WaitAll vs WaitAny

I am little bit confuse for WaitAll and WaitAny. I am trying to get exception but when i do WaitAll it return exception but When use WaitAny returns nothing.And necessary is that if any of task complete work done.Is their any Replacement of…
shaair
  • 945
  • 12
  • 24
4
votes
1 answer

Does Parallel.ForEach use threads from the ASP.NET thread pool?

I've read that using Task.Run in an ASP.NET web app was a bad idea as it uses another thread from the thread pool and hence prevent this particular thread from being used to serve a request. Isn't the same situation with Parallel.ForEach? Won't it…
4
votes
2 answers

Is an Implemenation Depending on Access to Modified Closure Undesirable?

I believe that I understand what a closure is for an anonymous function and am familiar with the traditional pitfalls. Good questions covering this topic are here and here. The purpose is not to understand why or how this works in a general sense…
Daniel King
  • 224
  • 1
  • 10
4
votes
1 answer

Is there any way to see the full stack trace across multiple threads?

In C# multi-threaded programming, when method A() calls method B() in a new thread, e.g. by using something like this: Task A() { // ... // I want B to run in parallel, without A() waiting for it. Task.Factory.StartNew(B); } void…
4
votes
2 answers

Ordered parallel execution

I have an ordered list like [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. I am passing it to a Parallel.ForEach statement. Can I somehow achieve the following ordering of execution of buckets like: process first 3 items [1, 2, 3] where ordering in bucket itself…
Giorgi Nakeuri
  • 35,155
  • 8
  • 47
  • 75
4
votes
1 answer

Thread Safety in .NET TPL Dataflow Source

I was looking at the implementation for some parts of the .NET TPL's "Dataflow" library out of curiosity and I came across the following snippet: private void GetHeadTailPositions(out Segment head, out Segment tail, out int headLow, out…
4
votes
0 answers

In a Unit Test how to control (pause, resume) internal background Task of the object under test

To give the generic question some flesh I have the following simple class to write my results to e.g. file: class ResultWriter { private BlockingCollection buffer; public ResultWriter(TextWriter writer, int bufferSize) { …
4
votes
2 answers

Why is the throughput of this C# data processing app so much lower than the raw capabilities of the server?

I have put together a small test harness to diagnose why the throughput of my C# data processing application (its core function selects records in batches of 100 from a remote database server using non-blocking IO and performs simple processing on…
Dan Hermann
  • 1,107
  • 1
  • 13
  • 27
4
votes
1 answer

Converting my C# BlockingCollection based code to TPL dataflow

I have a specific problem that i am sure can be solvable using TPL dataflow. I am just new to this, so need your help expediting my understanding. My code is like this currently: where Process1, Process2, Process3 each are Task. Objects are passed…
Subhash Makkena
  • 1,909
  • 2
  • 13
  • 15
4
votes
1 answer

C# synchronization between async tasks with infinite while loop?

I have one async task running an infinite loop doing some realtime processing: private async void RealTimeProcessingAsync() { while (true) { //.... Tmstaus status = await ReadStatusAsync(); switch (status) { …
Amordad
  • 43
  • 1
  • 4
4
votes
1 answer

TPL Dataflow Resources not released

I have a flow setup in the following way: _publisherQueue = CreateBuffer(); var batchingBlock = CreateBatchBlock(options.BatchSize); var debounceBlock = CreateDebounceBlock(options.DebounceInterval, batchingBlock.TriggerBatch); var publishBlock =…
4
votes
2 answers

How to do an async call to action method in MVC4

I have the following scenario here. How can make some parallel processing while the DB call runs asynchronously. /// /// Async query EF6.0 /// /// public async Task AsyncQuery() …
4
votes
2 answers

Completion in TPL Dataflow Loops

I have a problem with determining how to detect completion within a looping TPL Dataflow. I have a feedback loop in part of a dataflow which is making GET requests to a remote server and processing data responses (transforming these with more…
ajk
  • 41
  • 7
4
votes
3 answers

Notify task when other tasks complete

.Net TPL experts, Note: Cannot use DataFlow library; no add-ons allowed. I have four tasks as shown in the diagram below: task_1 (data_producer) -> reads records from a large file (>500000 records) and adds records to a BlockingCollection task_2,…
bdcoder
  • 3,280
  • 8
  • 35
  • 55
4
votes
3 answers

Task is ignoring Thread.Sleep

trying to grasp the TPL. Just for fun I tried to create some Tasks with a random sleep to see how it was processed. I was targeting a fire and forget pattern.. static void Main(string[] args) { Console.WriteLine("Demonstrating a…
Janus007
  • 366
  • 4
  • 11