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.
task-parallel-library
6,269
questions
2
votes
1
answer
70
views
Ensure that dotnet Tasks are stopped when they go out of garbage collector scope
I have a background task that I am modeling with a Task and which is stopped with an IAsyncDisposable.
// implementation
public sealed class Worker : IAsyncDisposable
{
private readonly ...
1
vote
4
answers
81
views
What is the proper way to convert Task to Task<T>?
I use a library that takes Task<T>, but sometimes I have to pass just Task, which I have to convert to Task<int>. What would be the more efficient/recommended option for converting the ...
0
votes
0
answers
50
views
Resetting/reusing a TaskCompletionSource
I have ClassA that has a property called GetData that returns a TaskCompletionSource Task:
private TaskCompletionSource<Data> _taskCompletionSource = new();
public Task<Data> GetData => ...
0
votes
0
answers
24
views
Task.WaitAll using Task.Run with async/await vs without [duplicate]
I am trying to understand how the code below would behave differently if the functions used in Task.Run were not async/await when calling GetAllData.
Am I correct that GetAllData will behave the same ...
1
vote
2
answers
77
views
How to produce multiple outputs in TPL Dataflow block before completion
I have this case where I am trying to build a pipeline using TPL Dataflow that could process a big number of items. At some point in the pipeline I need to batch items and send to the next block after ...
0
votes
2
answers
79
views
Writing repeating parallel loops for animation, avoiding System.Threading.Tasks.Parallel.For
I am writing a plugin to Rhino which animates some ray-traced data. Rhino handles all the drawing; I just have to provide it with something to draw.
The following Animate function is called from the ...
-1
votes
2
answers
126
views
Avoid closures when calling Parallel.For()
I'm performing some element UI hit testing like this:
internal MyElement[] HitTest((double x, double y) point, double scale)
{
ConcurrentBag<MyElement> geoms = new ConcurrentBag<...
0
votes
2
answers
134
views
Options to achieve parallel execution in C#
I have a use case where I need to process n number of operations, which involves other I/O operations.
Method 1: Uses ConcurrentBag<T>.
But worried that the I/O operations in the ...
0
votes
0
answers
33
views
.NET 6 - Accessing Rx Subject Element Concurrently And RAM Optimization While Using TCPClient
I have a .NET 6 project that reads market data from remote socket via TCPClient, process the data, and streams the processed data as socket. But the trick is, there are 2 markets. One is for delayed (...
0
votes
0
answers
43
views
Using TPL Dataflow with IDisposable
I have a multi-step, branching pipeline using TPL Dataflow, that I would like to get working with Unified Logging (through Azure Application Insights).
My issue is that the APIs at my disposal (no pun ...
-1
votes
2
answers
62
views
Parallel Tasks - Run Parallel threads but dont wait for other Tasks to complete and get the latest data from database
I am using Task library for running multiple tasks parallelly, and I am using below code to wait for other tasks to complete.
Parallel.ForEach(DatafromDB,
item => { DownloadSSR(mediator, ...
1
vote
3
answers
146
views
Parallel.ForEach with retries not showing all the values
I implemented a sample application to see the behavior of the retries inside a Parallel.ForEach loop. As per my observations following application not showing all the values inside the array, in the ...
0
votes
2
answers
146
views
Async/Await exception handling confusion
I'm trying to understand async/await in .net8, especially exception handling and I'm running into some confusion, especially regarding the documentation as while it specifies some of the approach it ...
0
votes
1
answer
70
views
Return new task with return value, using the Task constructor with async action
Maybe someone can explain, why this is working:
var task = new Task(async () =>
{
var noSolution = await AsyncMethodWithBoolReturnValue();
if (noSolution)
{
await ...
0
votes
0
answers
58
views
.NET Core : trigger multiple methods to execute after x seconds
In C# in .NET Core Web App, I want to trigger a method to execute after a specific amount of time (seconds / minutes).
I need to "schedule" a large number of such methods executions (500-...