Questions tagged [task-parallel-library]

The Task Parallel Library is part of .NET 4 and .NET 4.5. It is a set of APIs to enable developers to program asynchronous applications.

Filter by
Sorted by
Tagged with
2 votes
0 answers
327 views

What is better - using SerialPort with or without await/async methods?

I'm having an implementation using SerialPort in C# using Visual Studio 2019. I'm using it in a Windows Application, using .NET Framework 4.7.2. When I open and ...
user avatar
2 votes
0 answers
54 views

Is there a more elegant syntax using "Task.WaitAll" for 2 tasks and timeout

I'm using the SerialPort in C# using Visual Studio 2019. My SerialPort has 2 "pump" tasks, which are private members of my SerialPort, and are started during an Initialization method: ...
user avatar
1 vote
1 answer
111 views

What is wrong with this CancellationTokenSource example

Anybody mind providing an opinion on whether or not this is a good or bad example of Task Cancellation and why. I have my own opinion and I've been told that its baseless, just trying to find out who ...
user avatar
1 vote
1 answer
144 views

Execute .NET Core 3.1 background worker tasks simultaneously

I have following code: ...
user avatar
  • 13
3 votes
3 answers
468 views

Throttled execution of an enumeration of Tasks

Example of use: var users = await usernames.SelectTaskResults(GetUserDetails, 4); where GetUserDetails(string username) is a ...
user avatar
1 vote
1 answer
113 views

Render multiple SSRS reports in parallel

This service takes in a report request object that can contain multiple reports that need to be rendered. This code works but I'm not sure if I've implemented anything wrong. Note the ...
user avatar
0 votes
0 answers
107 views

Is the right usecase implemenation of ValueTask and Task in C#

I am trying to understand the right usage of Task vs ValueTask in .NetCore2.0(+) or C# 7.0(+) Task - Is a class/object types & uses heap memory should be used in async method when the operation ...
user avatar
  • 161
4 votes
1 answer
65 views

In-proc event dispatching through IoC container

Here is the sender and handler interfaces: ...
user avatar
  • 6,123
5 votes
1 answer
336 views

Parallel Calls to External WCF Service - ASP.NET Web Api

I have come across a situation where I feel running some code in parallel will greatly improve performance, but I am concerned about the implementation and am looking for some confirmation. Take the ...
user avatar
  • 51
2 votes
1 answer
223 views

A method that calls multiple async tasks with error handling, done the right way?

I've got a method, CheckForValue(), that uses named pipes to send a message to another process running locally, and then receive a message from that process, ...
user avatar
1 vote
1 answer
256 views

C# extension method to do some action if a target operation takes too long time to finish

I have a potentially long running operation and I want to trigger some action if takes too long time. Also I want to reuse this logic. Operation to check: ...
user avatar
4 votes
1 answer
114 views

Updating items in a list from a blocking source asynchronously

This is a Windows forms application. this.Server.GetLogMessages() will block if there are no messages to get, so I want this in a separate thread. I'm putting the ...
user avatar
  • 270
4 votes
2 answers
87 views

Creating an app to simulate load

I am writing an app that is supposed to simulate load on our web api and NServiceBus(particular) service. This is the first time I am writing an application like this. It appears to run ok, however ...
user avatar
  • 143
1 vote
1 answer
83 views

Invoking subscribers of an action in parallel c#

I have a questions as to the proper way to structure the code below. This snippet of code is used within a socket class which is intended to be a high performance socket. Many data handlers subscribe ...
user avatar
  • 161
0 votes
2 answers
126 views

Comparing performance between thread, task, parallel

I wrote some function to compare the duration taken for 1000 loops. Just wondering if the comparison is right? For the thread, I want to set to maximum 3 thread. Thread is ...
user avatar
4 votes
1 answer
57 views

Multi-threading with TPL - Access Internal Class Properties

I am using the TPL library to parallelize a 2D grid operation. I have extracted a simple example from my actual code to illustrate what I am doing. I am getting the desired results I want and my ...
user avatar
  • 43
1 vote
2 answers
291 views

C# Ping - Checking availability of hosts

Simple Console Application for checking if one of the hosts is available. The implementation should be for around 5 hosts to check with different response times and the method should return fast when ...
user avatar
2 votes
0 answers
85 views

Execute asynchronous read in parallel

I found it useful to execute multiple reads in parallel using a set of my extension methods for TaskFactory, which could be used as: ...
user avatar
  • 6,123
4 votes
1 answer
307 views

Iterate through Expression Tree

I'm trying to build an iterator (enumerator) that can select specific elements in an Expression tree by traversing the tree and deferring further iteration until ...
user avatar
  • 141
2 votes
0 answers
85 views

Retry HttpClient request without handlers

I have a server and client application. In the client application, there are HttpRequestException class exceptions on requests. As it seems to me - these exceptions happen in isolated cases and not ...
user avatar
2 votes
0 answers
117 views

Concurrent execution and coordination of C# tasks

I have a class, 'TaskCoordinator' which has 'BaseTask's applied to it. The BaseTasks have OnStarted, OnFinished and OnCancelled events which are triggered to notify the calling class of their events....
user avatar
  • 21
1 vote
1 answer
101 views

Async Tcpwriter and Reader

I currently have a class that I want to serialize/deserialize messages sent to this socket. My plan was to use Task.WhenAny() to monitor 2 tasks (Either watch ...
user avatar
  • 79
1 vote
0 answers
1k views

Some questions about a simple asynchronous socket client [closed]

I am having a hard time to come up with a simple TCP client, that should use one socket and two threads (one for sending and one for receiving). As using TPL tasks is the way asynchrony should be ...
user avatar
5 votes
2 answers
204 views

Async concurrency prevention class

Because I'm quite naive regarding C#'s Task Asynchronous Programming and concurrency in general, and because it's so difficult to test, I'm concerned about the safety of this code. It's likely that ...
user avatar
  • 151
5 votes
1 answer
196 views

Scraping an parsing jockeys data using Task.Run

I started to have HUGE doubts regarding my code and I need some advice from more experienced programmers and architects. On the button click, the application runs a method, that is running a ...
user avatar
  • 81
7 votes
1 answer
1k views

Usage of TPL vs Parallel.ForEach() on file processing

i've been working on an implementation of a my own from scratch set of library Astron and I wanted to get my TPL usage reviewed because i'm not confident with this technology :/ My app is currently ...
user avatar
  • 153
5 votes
1 answer
3k views

SemaphoreSlim extension method for safely handling cancellation and disposal

I have often found myself using a try {semaphore.Wait()} finally {semaphore.Release()} pattern when using a semaphore, so decided I wanted to try and write an ...
user avatar
1 vote
0 answers
735 views

Sending device data of 10k items with Parallel.ForEach

I have a deviceList of more than 10k items and want to send data by calling another method. I tried to use Parallel.Foreach but I'm not sure is this the correct ...
user avatar
  • 119
6 votes
2 answers
1k views

Parallel FTP client

I was given the task to download files for a FTP server. The download should be fairly fast. 15 parallel connections can be used. I have used FluentFTP as the ...
user avatar
  • 303
1 vote
1 answer
125 views

Asynchronous wrapper for database connection

I'm using a database that has a library for access to it. Connection is done synchronously, it's blocking and I do not have a way to abort it. To connect, I have to write: ...
user avatar
  • 143
1 vote
1 answer
132 views

Receiving and sending notifications from database

I'm not much familiar with Task Api programming in C#. Can anyone review my following code? The following is a ElapsedEventHandler of a ...
user avatar
1 vote
0 answers
600 views

Using up to 15 connections to synchronize files from a FTP server with local files

Task: Create a service which will synchronize files on FTP server with files on local drive. FTP server allows up to 15 concurent connections Synchronize the files as fast as possible Files on FTP ...
user avatar
  • 303
3 votes
1 answer
257 views

Repeating a task that may fail (in parallel)

Almost like this question here, I'm playing with some methods that may fail, but in my case, the method failing is not a exceptional case; it just means I need to try running it again. The method I'm ...
user avatar
  • 751
2 votes
0 answers
57 views

Task based GameObject recorder for networked game

I've recently been dipping my toes in to async code so I'm not 100% sure if there's a better way to do this, or if I'm going to run into problems down the road. I plan on using the following class in ...
user avatar
  • 21
1 vote
1 answer
126 views

Concurrent usage of resources

Please take a look at the following code. This is my attempt at understanding concurrent applications. ...
user avatar
6 votes
2 answers
5k views

ForEachAsync extension method (a way to run an async operation on each item of a sequence in parallel)

In a recent project I worked on we faced some issues due to an excess of parallelization (thousands of threads were created and the overall result was a degradation of performance and several spikes ...
user avatar
1 vote
1 answer
70 views

Dispatch multiple publishers to single handler with result

This code defines a MessageBus used to handle messages from many producers to a single consumer. The bus allows multiple publishers to send messages asynchronously ...
user avatar
  • 111
5 votes
1 answer
161 views

Async/Await Computation Expression

When writing asynchronous code in F#, one often needs to call methods in the .NET BCL that return Task or Task<T> rather ...
user avatar
4 votes
0 answers
60 views

Coordination function

This function started very clean but I had to add requirements: Added a Stopwatch to only update the caller periodically. I guess that responsibility could be ...
user avatar
1 vote
1 answer
2k views

Creating membership list with Parallel.ForEach [closed]

I had a foreach loop which used to loop Membership users and create list of a custom class. Following was the for loop: ...
user avatar
3 votes
1 answer
9k views

Simple server using async and HttpListener

I have a program that controls a custom machine. I wanted to add some simple HTTP comms so I could control it from the network or other programs. My server class is: ...
user avatar
2 votes
3 answers
2k views

Writing to file using TPL with ConcurrentQueue

Here is a sample code to explain the approach I am going for. ...
user avatar
  • 157
11 votes
1 answer
410 views

Testing a list of proxies for validity concurrently

I have a class that tests a list of proxies for validity concurrently, which I have created in 2 different ways, one utilizing Parallel.ForEach and the other using a TPL Dataflow ActionBlock. I am ...
user avatar
  • 425
3 votes
2 answers
108 views

parallel bing maps searching

Please assist and review the following task. There are many geographic data to be found using the Bing Map server. It is necessary to collect data, parse bing response and store it in one of two ...
user avatar
3 votes
2 answers
6k views

Running parallel tasks until they're done

The General Idea I wish to simulate something which works like Java's ThreadExecutor, but as a first step, I would like to run a fixed number of identical tasks in ...
user avatar
6 votes
1 answer
4k views

Process List asynchronously with SemaphoreSlim for throttling extension method

I've got some methods that follow a similar pattern, and wanted to abstract some of the logic away into an extension method. Specifically, I am processing lists of objects with the TPL, and throttling ...
user avatar
  • 425
1 vote
2 answers
197 views

Parsing NuGet packages.config with Parallel.ForEach

Below is a file parser for old style nuget package configuration files. The Parallel.ForEach is probably overkill; in most cases its fast enough without. However, ...
user avatar
  • 165
4 votes
1 answer
2k views

PauseOrCancelTokenSource

I added this implementation of PauseToken and PauseTokenSource to my project from this MSDN blog post: Cooperatively pausing async methods Since I will usually be passing in both a PauseToken and a ...
user avatar
  • 425
2 votes
2 answers
369 views

Task Execution with Cancel Logic

In my assignment I am executing a long running NodeJs script from C# using EdgeJs. Since the script may take a long time to execute, I also want to provide user an option to Cancel the script ...
user avatar
1 vote
0 answers
196 views

F# Operation Framework (Railway-Oriented Programming + Task/Async/Lazy)

I recently published the initial version of what is effectively my first open-source software package, a Railway-Oriented Programming Framework for F# that encapsulates Tasks, Async Workflows, and ...
user avatar