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.
150 questions
51
votes
3
answers
6k
views
I'm in your .zips crackin' your passwords
As an attempt to learn multithreading better, I wrote a program to crack the password of a ZIP file. It is sort of slow, processing a three-digit password of the 95 printable ASCII characters in ...
28
votes
3
answers
64k
views
Websockets client code and making it production-ready
The following code is helpful to anyone who uses websockets in general... and is probably good template for anyone getting started in this area. I'd like to flesh this out into something that is more ...
22
votes
5
answers
37k
views
A TaskScheduler that always run tasks in a specific thread
The following is an TaskScheduler that always run tasks in a thread it maintains.
When created, a name of the thread was specified. Once you schedule the first task,...
13
votes
1
answer
27k
views
Filtering a collection by an async result
I'm trying to do something like this:
var loudDogs = dogs.Where(async d => await d.IsYappyAsync);
The "IsYappyAsync" property would return a ...
13
votes
2
answers
10k
views
BackgroundWorker vs TPL ProgressBar Exercise
I wanted to fiddle around with the BackgroundWorker and Task classes, to see how I would implement a given task with these two ...
13
votes
0
answers
3k
views
Socket application using TPL
This is an application I wrote that allows multiple TCP clients to share a single TCP connection to a remote server (hosted project, and a demo). Traffic generated by the server is forwarded to all ...
12
votes
3
answers
1k
views
WhenAll for .NET 3.5
I am trying to write a version of Task.WhenAll for .NET 3.5 using the "Task Parallel Library for .NET 3.5". This is what I came up with. Is there a better way of ...
12
votes
2
answers
854
views
Wait, is that variable ever assigned?
One of the inspections we wanted to implement in Rubberduck for the next release, is one that finds all unassigned variables in a VBA project.
Implementing this inspection has been ...complicated (it'...
12
votes
1
answer
10k
views
Throttle actions by number per period
I want to throttle asynchronous actions at a specific maximum rate of n actions per t period, and have pending actions wait until there is a free slot (rather than drop them). I want to receive the ...
11
votes
3
answers
671
views
Multithreaded Mandelbrot Generator Ver 2
Update: Version 3 is here.
My first version was an answer I provided to EBrown for his original post titled "Multithreaded Mandelbrot Generator". My answer had many good things in it, but I felt ...
11
votes
3
answers
6k
views
Parallelized download of multiple images based on URL
I decided to rewrite a previous program of mine from scratch. The result is a lot better than the previous one but now that it seems like it is working I want to optimize it (hopefully it is not too ...
11
votes
2
answers
4k
views
TaskScheduler that uses a dedicated thread
I'm trying to implement a TaskScheduler that runs all tasks in the order they are submitted, on a single dedicated thread. Here's my implementation, using a ...
11
votes
2
answers
16k
views
Console chat server
I'm just looking for feedback on correctness of my understanding of async/await. I'm curious about the Task.Run inside of the ...
11
votes
2
answers
4k
views
Asynchronous retry method
I've written an asynchronous retry method as an answer for this question. I'd like to get your opinion of the implementation and whether there are better ways to implement this. You could also ...
11
votes
1
answer
442
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 ...
10
votes
1
answer
49k
views
Correct approach to wait for multiple async methods to complete
I have an IWorkflow interface defined as follows:
...
10
votes
1
answer
20k
views
Async Queue Processing
I have a Queue that needs to try to process when anything updates in it (add, remove or update).
However, I don't want any of the callers to wait while the ...
9
votes
1
answer
13k
views
Writing highly asynchronous code
I am writing a new web service that will be performing a lot of large data load operations. To do so I am moving the data to a temporary table then merging the data in to the live data via a stored ...
8
votes
1
answer
7k
views
Implementing a cancellable "infinite" loop
I'm making a Windows service that watches a directory for new files to process them.
I hit a race condition between the file copying going on and me trying to process it. Going by a SO answer I wrote ...
8
votes
2
answers
13k
views
Listen to multiple RabbitMQ queue by task and process the message
Single app which listen to multiple RabbitMQ queue and process the message. This is working fine but not sure this implementation is right one or I am missing something.
Implementation is inspired ...
8
votes
1
answer
10k
views
TPL inside Windows Service
I need to perform few tasks inside a Windows Service I am writing in parallel. I am using VS2013, .NET 4.5 and this post shows that TPL is the way to go.
I was wondering if anyone can tell me if I ...
8
votes
1
answer
15k
views
C# 5 Async Await .Task.Factory.StartNew cancellation
I have the async code that implements cancellation token. It's working but Im not pretty sure if this is the right way to do it so I just want feedback about it.
Here is the actual code:
...
7
votes
1
answer
35k
views
Starting a fire and forget async method
Sonar/FxCop are telling us that we shouldn't use void async methods. That's ok.
This is the current implementation:
...
7
votes
3
answers
250
views
Downloading files from a Mozilla file server via FTP
All classes on GitHub repo
This is the code for downloading files from a FTP-server running Mozilla Fileserver.
FtpItem is the interface for the two classes ...
7
votes
1
answer
2k
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 ...
6
votes
1
answer
9k
views
Monitoring progress in Parallel.ForEach every minute
I'm using Parallel.ForEach to download 500K URLs and I want to monitor the number of URLs that have been successfully downloaded each minute.
...
6
votes
1
answer
30k
views
Simple parallel foreach loop code correctness
I have both the regular for each loop and its equivalent paralleled version. The loop simply iterates through a collection, looking for the rate key in a local db ...
6
votes
2
answers
6k
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 ...
6
votes
2
answers
6k
views
Is Concurrent Collection Needed Here?
I'm playing around with switching some code to using Parallel.ForEach and I have a question about whether I need to be concerned about the effects of concurrency ...
6
votes
2
answers
2k
views
High udpclient CPU use
I have a bunch of different ports I want to listen on and the iterate over the available data to send to a Dataflow pipeline. In total I'm listening on 14 ports. I'm looking for any advice on how to ...
6
votes
2
answers
4k
views
Task.Finally extension, good, bad, or ugly?
I wrote this, and it has helped to avoid the 'Some exception weren't handled' problem. Is there something glaringly wrong with this that I might have missed?
...
6
votes
2
answers
2k
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 ...
6
votes
2
answers
2k
views
Parallelizing bitmap methods
I created a class called QuickBitmap to quickly get/set pixels in a Bitmap object. Using intertops I'm able to safely lock/unlock the bits of the ...
6
votes
2
answers
7k
views
Producer / Consumer implementation for Parallel Processing in the TPL
I've stripped this down to its bare bones removing stopping/cancellation logic etc... to keep it simple.
The Producer is a very simple class containing a timer. At ...
6
votes
1
answer
9k
views
Using Task<T> and actions for simple threading?
My question is regarding a rather inelegant solution to a problem that I came up with a while ago.
I was making a Winform Application to access active directory among other things and needed to ...
6
votes
1
answer
5k
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 ...
6
votes
1
answer
7k
views
Consuming chunks from ConcurrentQueue
I need to implement a queue of requests which can be populated from multiple threads. When this queue becomes larger than 1000 completed requests, these requests should be stored into a database.
<...
6
votes
1
answer
8k
views
Use and understanding of async/await in .NET 4.5 +
I am just about to embark upon a massive job of multi-threading a cost-engine. I could use TPL of which I am very familiar, but would like to leverage the async/<...
6
votes
1
answer
303
views
Server that supports two types of connections
I'm wonder if my approach is correct. I'm trying to make a WinForms server that processes data from 3 sides:
from bluettoh (InTheHand library) as source data which I need to process in server
to ...
6
votes
1
answer
231
views
Processing input in background while user is typing
Use case
A GUI with 2 controls:
An input control for text (a DNA sequence) that should be analyzed
A result control that displays the analyzing result of the entered text
The analysis takes 2-3 ...
5
votes
1
answer
208
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 ...
5
votes
1
answer
5k
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 ...
5
votes
1
answer
873
views
Splitting a UTF-8 string into equal-sized byte-arrays for parallel processing
Based upon a question from Stack Overflow, I wanted to expand on the answer I wrote and define a solution that would support ordering the strings (after processing).
So this starts off with a basic <...
5
votes
2
answers
11k
views
Tasks: exceptions and cancelation
I need to do a long running task. I've done this by executing a Task while there's a loading box on the UI. When an exception is thrown, I want to stop the task and show a msgbox to the user. If ...
5
votes
1
answer
720
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 ...
5
votes
2
answers
258
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 ...
5
votes
1
answer
177
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 ...
5
votes
1
answer
336
views
Multithreaded Mandelbrot Generator Ver 3
I thought Ver 2 was fairly solid but ending up modifying all but one method for Ver 3. Performance for Generate is the same, but I was able to simplify the method ...
5
votes
1
answer
6k
views
TPL Dataflow BatchBlock with Batch Size & Timeout
I needed BatchBlock with support for timeout (act greedy on what it received at that time) and by some search and study, this is the outcome.
What are drawbacks or ...
5
votes
1
answer
705
views
Non locking UI code in WP8
I've recently started to delve into the world of windows phone 8 dev, and as a learning experience I've decided to make a stopwatch application. Now, given I've been a web guy most of my career, I've ...