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

How can I implement a lazy TaskCompletionSource?

If the Task exposed by my TaskCompletionSource may never get called how can I deffer computation of the Result unless and until someone awaits the task? For example, I want to block other async threads of execution until a ManualResetEvent is…
4
votes
3 answers

In Task Parallel Library: How to defer Task.TaskFactory.FromAsync task execution?

I have a method that returns a task like: public static Task SendAsync(this Socket socket, byte[] buffer, int offset, int count) { if (socket == null) throw new ArgumentNullException("socket"); if (buffer == null) throw new…
harmen
  • 163
  • 2
  • 8
4
votes
1 answer

Getting reference to original Task after ordering Tasks by completion?

I asked a question a while ago about a method that orders a List>> by their completion that also returns an int representing the index of the completed Task in the original List> given. I have the inkling that I might not need to…
KDecker
  • 6,928
  • 8
  • 40
  • 81
4
votes
1 answer

Best design for permanently and scheduled tasks

I have requirement where I need to have some tasks to run permanently while some other should just be run on a scheduled basis but I'm not sure what the best way to handle this scenario should be. For the scheduled jobs, I thought I'd use a Thread…
Thierry
  • 6,142
  • 13
  • 66
  • 117
4
votes
1 answer

How to consume chuncks from ConcurrentQueue correctly

I need to implement a queue of requests which can be populated from multiple threads. When this queue becomes larger than 1000 completed requests, this requests should be stored into database. Here is my implementation: public class RequestQueue { …
4
votes
2 answers

Is writing to a bool variable from multiple threads safe in C#?

I need to check if any iterations of a Parallel.ForEach reach a specific point. From my understanding the following would be safe if my bool was a volatile field, but it needs to be a variable in the enclosing method: bool anySuccess =…
Jussi Kosunen
  • 8,277
  • 3
  • 26
  • 34
4
votes
1 answer

Task Parallel Library - How do you get a Continuation with TaskContinuationOptions.OnlyOnCanceled to Fire?

I'm experimenting with the Task support in .NET 4.0 - specifically with the continuation support. What I'm perplexed about is that I can't figure out how to get a continuation with the TaskContinuationOptions.OnlyOnCanceled flag set to execute. If…
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
4
votes
4 answers

Encapsulating async method in Task.Factory.StartNew

I have a good understanding of Task and the async/await pattern but recently someone fixed a deadlock that he said was caused by : public async Task GetHttpResponse() { using (var client = new HttpClient()) { …
Linvi
  • 2,077
  • 1
  • 14
  • 28
4
votes
3 answers

Thread synchronization in the Task Parallel Library (TPL)

I am learning TPL and stuck with a doubt. It is only for learning purpose and I hope people will guide me in the correct direction. I want only one thread to access the variable sum at one time so that it does not get overwritten. The code I have is…
vic90
  • 89
  • 1
  • 8
4
votes
1 answer

Does Task.WhenAny prioritize some tasks over others?

When passing multiple completed tasks to Task.WhenAny does Task.WhenAny give a preference to which task completed Task will be returned?
Zachary Burns
  • 453
  • 2
  • 9
4
votes
1 answer

Are there any use cases for Task.Delay(-1)?

I wonder whether there are any use cases for Task.Delay(-1) or Task.Delay(TimeSpan.FromMilliseconds(-1)). According to respective documentations, that methods create tasks that wait indefinitely before completing. I know that await Task.Delay(...)…
Tomasz Maczyński
  • 973
  • 10
  • 24
4
votes
1 answer

Child Tasks Vs WaitAll

I am not sure what is the benefit of creating child tasks when I can have the parent task wait for all the tasks it created. I run the following code and it produced the same result in both cases. public static void Main(string[] args) { …
4
votes
3 answers

Is it acceptable practice to create Tasks with long delays?

I'm creating a scheduler to fire events at specific times of the day, and to do this I'm spinning up Tasks (one at a time, i.e. the 'next' schedule only) with a Task.Delay of anything up to a few days delay. For example, after the last event fires…
Detail
  • 785
  • 9
  • 23
4
votes
2 answers

Why can't I install my windows service - Specified service already exists

I wish I could put a grenade to my computer at this point. I'm so frustrated because I don't understand why my application won't install using installUtil. I've just looked through this link now: Windows Service Install Ends in Rollback and…
Sizons
  • 640
  • 2
  • 8
  • 24
4
votes
2 answers

Is there a TPL dataflow block that doesn't take input but returns output?

The title of my question says it all. I am looking for a TPL dataflow block that doesn't need an input. Right now I am using a transform block but it's input is unused.
1 2 3
99
100