370 questions
0
votes
2
answers
129
views
In C# 8 / Unity 2022, why is PLINQ SelectMany + Select + FirstOrDefault executed in sequential mode?
Here is the code in question:
var raw = Enumerable.Range(1, 10);
var candidates = raw.AsParallel();
var p1 = candidates.AsParallel()
.SelectMany(
ii =>
{
Debug.Log(...
-1
votes
1
answer
140
views
How to get results from List<T>.AsParallel() in C#
I have an asynchronous
async static public Task<int> Test(int x, int y)
{
await Task.Delay(1000);
return x;
}
And I try to run it in parallele on a list. I did like that:
var x = new[] { ...
4
votes
2
answers
266
views
Why does ToList() make a sorted order?
When I execute the following code:
using static System.Console;
var numbers = ParallelEnumerable.Range(0, 50);
WriteLine("\nNumbers divisible by 5 are:");
var divisibleBy5 = numbers
....
4
votes
0
answers
127
views
PLINQ behaves differently in .NET 8
Run the following code:
using System;
using static System.Console;
var numbers = Enumerable.Range(0, 31);
WriteLine("\nNumbers divisible by 5 are(using LINQ):");
numbers
.Where(num => ...
0
votes
0
answers
66
views
Is there a way to dynamically change DegreeOfParallelism in a PLINQ query?
I want to convert a large array of objects in parallel using PLINQ.
var outputs = inputs
.AsParallel()
.AsOrdered()
.WithDegreeOfParallelism(8) // make this number dynamic
.Select(...
0
votes
0
answers
57
views
How to trace ETW Events inside Parallel.ForEach in C#
Need your help to understand how can we log ETW events to track Task started & Task completed inside parallel.foreach. I basically need to see when event got fired.
I have gone through few ...
4
votes
3
answers
905
views
Using a partitioner in C# to parallel query a REST-API with pagination
I was wondering if my approach is good to query a REST-API in parallel because there is a limit on how many results can be obtained with one request (1000). To speed up things I want to do this in ...
2
votes
2
answers
287
views
PLINQ ForAll WithCancellation is not working
I wrote a PLINQ query that ends with the ForAll operator, and I used the WithCancellation operator in order to cancel the query midway. Surprisingly the query is not canceled. Here is a minimal ...
3
votes
2
answers
170
views
Exception is lost while consuming a PLINQ query
I observed a weird behavior while experimenting with a PLINQ query. Here is the scenario:
There is a source IEnumerable<int> sequence that contains the two items 1 and 2.
A Parallel LINQ Select ...
1
vote
1
answer
215
views
Find all the child nodes from self referenced DataTable using parent ID and update particular column on a bulk data
I have a self-referenced table like below.
key
parent
Description
A
NULL
B
A
C
B
D
C
And initially having 1 Key value.
Using this key value, I need to find all the child nodes recursively and ...
2
votes
1
answer
246
views
How to create a custom grouped / hashed PLINQ partitioner or parallel query
I am trying to process a list of file paths in parallel using PLINQ.
I have to process all files with the same name, excluding extension, in the same thread, as that thread may be renaming file ...
2
votes
2
answers
345
views
Memory leak in using PLinq AsParallel
I wrote a piece of testing code using AsParallel to concurrently read big files. It causes memory leak. It seems GC doesn’t recycle the unused objects as expected. Please see the code snippet.
...
2
votes
1
answer
271
views
PLINQ vs Sync Over Async: what is the difference?
I love PLINQ. In all of my test cases on various parallelization patterns, it performs well and consistently. But I recently ran into a question that has me a little bothered: what is the functional ...
0
votes
0
answers
31
views
Conditionally use PLINQ with minimal code duplication [duplicate]
I have some LINQ code that under some conditions, which I can test for, benefits from parallelization.
I would like to use PLINQ when such conditions apply, but also avoid to have all the processing ...
0
votes
1
answer
218
views
Converting Parallel ForEach into PLINQ to process list of Tasks [closed]
I am trying to load as many messages into a server fast as possible. I currently have this bit of code and to load 50000 messages to a MessagingServer it takes around 5 minutes. This is a list of ...
0
votes
0
answers
126
views
IQueryable (PLINQ) peek and group Linq methods to run in different tasks
I want to divide a IQueryable into several ones, like the image below, extracted from the explanation of the .AsParallel(). But instead of running all in parallel, I want to run some of them together, ...
0
votes
2
answers
164
views
C# How to use AsParallel conditionally or attach dynamically at runtime
this is a sample join between two datatable by LINQ
var JoinResult = (from p in dt.AsEnumerable()
join t in dtTax.AsEnumerable()
on p.Field<int>("...
0
votes
1
answer
69
views
Can I multithread a function for all entries in a list and return the list entry that gives the max value in O(n)?
I have a list of 3D X/Y/Z points, foundPoints and single 3D X/Y/Z point, rayOrigin. I'm looking to return the point from the list that is farthest from rayOrigin. It is likely that the list could ...
0
votes
0
answers
245
views
LINQ/PLINQ AsNoTracking / AsParallel Performance - Usage
I've read that if you only need to read entities (not to update them) it is better to use AsNoTracking().
As for AsParallel() some dude said it's always better to measure (e.g. Stopwatch) and to ...
3
votes
2
answers
187
views
Accessing value used in LINQ Select within a foreach
Given a list of IP addresses:
List<string> ipList = new List<string>(); //example: 192.168.0.1, 192.168.0.2, 192.168.0.3 etc.
I am attempting to loop over each IP in the list, in a ...
11
votes
1
answer
420
views
"using static" kills AsParallel
In the following code, if you uncomment the "using static" line, the query will not run in parallel. Why?
(Visual Studio Community 2019, .Net Core 3.1 / .Net 4.8)
using System;
using System....
1
vote
1
answer
1k
views
Parallel loop containing both async and synchronous
I've got a loop that needs to be run in parallel as each iteration is slow and processor intensive but I also need to call an async method as part of each iteration in the loop.
I've seen questions on ...
1
vote
2
answers
263
views
How to convert Parallel.For to PLINQ
Parallel.For(0, Height, new ParallelOptions { MaxDegreeOfParallelism = 6 }, y =>
{
int currentLine = y * BMPData.Stride;
for (int x = 0; x < Width; x = x + BPX)
{
var b = ...
1
vote
2
answers
1k
views
How to segmentate an IList<T> to segments of N size, without creating copies and without memory allocations?
I have a very large collection that implements the generic IList<T> interface and contains tens of millions of elements, and I would like to process them in parallel using PLINQ. I noticed that ...
0
votes
2
answers
91
views
Parallel search in 2 collection
So, I have 2 collection (the first - all symbols and the second - searching)
IEnumerable<MarketSymbol> metadata; // 1
string [] symbols; // 2
For example,
class MarketSymbol { ...
0
votes
1
answer
891
views
Is Task parallel library, PLINQ or Concurrent Collections used in Web Applications built with Asp.Net core Mvc or Razor Pages?
I am beginner in C# , .Net core. So, I do have very limited knowledge over this advance topics (Task parallel library, PLINQ or Concurrent Collections). If my question seemed like idiotic, then I am ...
1
vote
0
answers
1k
views
Parallel.ForEach and AsParallel().ForAll (freeze)
Good afternoon, dear forum users! I have used PLINQ a lot and have never had a problem with it until now. I am writing a universal logger to use in several projects that could write logs ...
1
vote
1
answer
2k
views
Arithmetic operation resulted in an overflow even after applying unchecked
Why do I get an overflow exception even if I apply the unchecked operator on an expression?
return GetCharStream().AsParallel().Aggregate<char, int[], int[]>(() => new int[26],
(ca, c) =&...
0
votes
1
answer
291
views
.NET PLINQ vs Async Performance
Given this PLINQ code:
public static IEnumerable<Tuple<string, string>> PlinqFileProcessingLimitedCores(int nr_of_cores)
{
string archiveDirectory = @"C:\...
1
vote
0
answers
1k
views
Parallel LINQ over IAsyncEnumerable<T>?
Any official or stable 3rd party library that supports using AsParallel over an IAsyncEnumerable<T> (.NET Standard 2.1) ?
I don't want to wrap an IAsyncEnumerable<T> to an IEnumerable<...
-2
votes
1
answer
65
views
error textBox3 ACCESSED FROM A THREAD OTHER THAN THE THREAD IT WAS CREATED ON while executing Plinq query
i have a method in another class that select all the lines that contains given char from textbox2,and print it to textbox3 on button_click but i'm having this error (textBox3 ACCESSED FROM A THREAD ...
1
vote
1
answer
640
views
Impact of using AsParallel() and AsSequential() in the same query? C#
I was going through PLINQ in one of the books and it said:
If you have a complex query that can benefit from parallel processing
but also has some parts that should be done sequentially, you can ...
0
votes
1
answer
503
views
Replace Task.WhenAll with PLinq
I'm having a method which calls a WCF service multiple times in parallel. To prevent an overload on the target system, I want to use PLinq's ability to limit the number of parallel executions. Now I ...
0
votes
0
answers
17
views
Put a variable in plinq statement
I'm new with LINQ and I try to make a statement like this where I have a variable called status and takes a different value but how can I do this because I have this error
Error CS0029 Cannot ...
1
vote
0
answers
399
views
C# PLINQ WithDegreeOfParallelism always load 100% CPUs
I have changed my LINQ query in C# .NET 4.7, introducing AsParallel() and WithDegreeOfParallelism().
My CPU is an i7 with 4 cores and 8 logic processors.
With any value in WithDegreeOfParallelism (...
0
votes
1
answer
427
views
Plinq and linq performance comparison c#
Can someone explain for me why PLinq is better than normal linq in first example but worst in the second? I see the only difference is Thread.Sleep() at ExpensiveComputation() function
using System;
...
0
votes
1
answer
605
views
Joining two lists with nested lists
Trying to find a way to join two lists along with nested lists through LINQ or PLINQ.
I have List A, List B and wanted to join these two with their parent and child properties.
I have tried the ...
0
votes
1
answer
114
views
How is the PLINQ AsParallel function passing data to a function when called within the same scope
Using IronPython, I am calling some function in parallel that is within the same function the parallelized data is in to keep it in the same scope.
In multiprocessing of CPython it is pretty clear ...
2
votes
1
answer
402
views
Why is combining Task.Run and plinq so slow?
I found that combining Task.Run with plinq is extremely slow so I made a simple experiment:
int scale = 32;
Enumerable.Range( 0, scale ).AsParallel().ForAll( i => {
Enumerable.Range( 0, scale ...
0
votes
0
answers
229
views
What is the difference between ForAll and Select in PLINQ
In the intro to PLINQ, the docs seem to show two different ways of getting data back from a process unordered. In one case, AsParallel can be used with Unsorted and the Select or SelectMany method. ...
0
votes
1
answer
60
views
Task execution dependent upon the waiting mechanism?
Here's the pseudo-code that I'm running:
Variant #1:
List<Task> tasks = new List<Task>();
foreach (...)
{
Task task = Task.Run(() =>
{
doWork();
});
tasks.Add(...
1
vote
2
answers
499
views
How to fix ArgumentException in Windows-API-Code-Pack?
I've created an application that reads properties from files using the Windows-API-Code-Pack from this package. I'm having an issue when retrieving properties
var width = fileInfo.Properties....
3
votes
2
answers
877
views
How can I report progress from a PLINQ query?
I would like to report progress from a long running PLINQ query.
I can't really find any native LINQ method that allows me to do this (as was implemented for cancellation).
I have read this article ...
0
votes
2
answers
285
views
Parallel LINQ UnauthorizedAccessException when Aggregating results
I am searching in parallel using LINQ to find pattern matching files.
public class ParallelLinq
{
public IList<string> SearchFolders = new List<string>
{
@"C:\Windows" //...
0
votes
0
answers
92
views
How to determine if threads are being blocked by PLINQ Query?
I am trying to find a Levenshtien match between two datasets. I try to find the edit distances of a ListA which contains thousands of values against another ListB which contains millions of records.
...
1
vote
1
answer
208
views
How do I use Linq to select the top/bottom N contestants in a Ranked Choice Vote?
I am trying to use Linq (and eventually parallel Linq) calculate the top N ballots in a Ranked Choice Vote / Alternative Vote
I'm using the following code to generate several ballots with a ...
0
votes
0
answers
194
views
Under what conditions does .NET decide to cancel a PLINQ task?
I've had a look around for some documentation, and all the documentation appears to suggest the following...
PLINQ tasks do not have a default timeout
PLINQ tasks can deadlock, and .NET/TPL will ...
0
votes
2
answers
158
views
Occasional performance drops in linq queries to concurrent bag
I am currently investigating some severe performance drops in an application.
Performance drops are of a strange kind - several iterations in a row work quite fast, but then there are one iteration ...
-2
votes
2
answers
411
views
PLINQ slower than actual Linq for this snippet
Below is the code snippet. EF6 is used.
var itemNames = context.cam.AsParallel()
.Where(x=> x.cams ==
"edsfdf")
.Select(item => ...
2
votes
2
answers
112
views
Parallel ordered consumable
I would like to process some items in parallel. This processing is independent (order does not matter) and returns an output. These outputs should then be relayed back in order as quickly as possible.
...