parallel.foreach

winforms: updating progress with a parallel.foreach

旧巷老猫 提交于 2019-12-24 06:01:50
问题 I haven't seen any posts pertaining to my issue, so I apologize if I post a question already asked. I have a windows form program, c#, that checks stocks and does analysis. The main form launches another form, via a new thread and ShowDialog. While it's loading, it's running a parallel.foreach. In that parallel.foreach, I'd like to show progress on the main form. I've run into cross-threading issues, and added invoke, although it doesn't appear to be thread-safe as it seems to be deadlocking

stop Parallel.ForEach immediately

人走茶凉 提交于 2019-12-24 03:16:13
问题 I have a problem stopping a Parallel for each loop. I am iterating over a set of about 40.000 DataRows retrieved from a table, and I need to stop my loop immediately when I have 100 items in my resultset. The problem is that when I trigger the Stop method on the ParallelLoopState, the iteration is not stopped immediately, causing inconsistency in my resultset ( either to few or to many items). Is there no way to make sure, that I kill all threads, as soon as I hit stop? List<DataRow> rows =

C# Parallel.Foreach equivalent in Python

孤人 提交于 2019-12-23 09:03:26
问题 I have 96 txt files that have to be processed. Right now I am using a for loop and doing them one at a time, this process is very slow. The resulting 96 files, do not need to be merged. Is there a way to make them run in parallel, ala Parallel.foreach in C#? Current code: for src_name in glob.glob(source_dir+'/*.txt'): outfile = open (...) with open(...) as infile: for line in infile: --PROCESS-- for --condition--: outfile.write(...) infile.close() outfile.close() Want this process to run in

Parallel request to scrape multiple pages of a website

孤人 提交于 2019-12-23 04:54:40
问题 I want to scrape a website with plenty of pages with interesting data but as the source is very large I want to multithread and limit the overload. I use a Parallel.ForEach to start each chunk of 10 tasks and I wait in the main for loop until the numbers of active threads started drop below a threshold. For that I use a counter of active threads I increment when starting a new thread with a WebClient and decrement when the DownloadStringCompleted event of the WebClient is triggered.

java 8 parallel stream Issue

前提是你 提交于 2019-12-22 17:53:36
问题 _logger.info("data size : "+saleData.size); saleData.parallelStream().forEach(data -> { SaleAggrData saleAggrData = new SaleAggrData() { { setCatId(data.getCatId()); setRevenue(RoundUpUtil.roundUpDouble(data.getRevenue())); setMargin(RoundUpUtil.roundUpDouble(data.getMargin())); setUnits(data.getUnits()); setMarginRate(ComputeUtil.marginRate(data.getRevenue(), data.getMargin())); setOtd(ComputeUtil.OTD(data.getRevenue(), data.getUnits())); setSaleDate(data.getSaleDate()); setDiscountDepth

How to know threadid for each thread spawn by parallel.foreach

て烟熏妆下的殇ゞ 提交于 2019-12-22 13:49:23
问题 I have a scenario something like this int arr[100]; Parallel.Foreach(arr, (a) => { some processing}); Now, this code will spawn 100 child threads, how can I know thread id for each child thread in "some processing" logic. 回答1: You could use Thread.CurrentThread.ManagedThreadId but note that your parallel foreach is not forced to actually create 100 threads. 来源: https://stackoverflow.com/questions/25369399/how-to-know-threadid-for-each-thread-spawn-by-parallel-foreach

Parallelizing IO Bound (Network) ForEach Loop

梦想与她 提交于 2019-12-22 07:59:30
问题 I have a few different ways of upload entire directories to Amazon S3 within my application depending on what options are selected. Currently one of the options will perform an upload of multiple directories in parallel. I'm not sure if this is a good idea as in some cases it sped up the upload and other cases it slowed it down. The speed up appears to be when there are a bunch of small directories, but it slows down if there are large directories in the batch. I'm using the parallel ForEach

How can I maximize the performance of element-wise operation on an big array in C#

浪子不回头ぞ 提交于 2019-12-21 17:07:07
问题 The operation is to multiply every i-th element of a array (call it A) and i-th element of a matrix of the same size(B), and update the same i-th element of A with the value earned. In a arithmetic formula, A'[i] = A[i]*B[i] (0 < i < n(A)) What's the best way to optimize this operation in a multi-core environment? Here's my current code; var learningRate = 0.001f; var m = 20000; var n = 40000; var W = float[m*n]; var C = float[m*n]; //my current code ...[1] Parallel.ForEach(Enumerable.Range(0

How can I assign a name to a task in TPL

随声附和 提交于 2019-12-21 03:19:08
问题 I'm going to use lots of tasks running on my application. Each bunch of tasks is running for some reason. I would like to name these tasks so when I watch the Parallel Tasks window, I could recognize them easily. With another point of view, consider I'm using tasks at the framework level to populate a list. A developer that use my framework is also using tasks for her job. If she looks at the Parallel Tasks Window she will find some tasks having no idea about. I want to name tasks so she can

Parallel ForEach with SQL inserts c#

試著忘記壹切 提交于 2019-12-20 03:52:12
问题 I have an object like the below but with a huge amount of data, we observed that it takes a long to be inserted into our SQL database as we were using normal foreach , the main idea is to insert each Department and get the generated identity number, then insert the nested employees assigned with that department ID. <Sample> <Departments> <Department> <Name>HR</Name> <Employees> <Employee> <Name>Marco</Name> </Employee> <Employee> <Name>John</Name> </Employee> <Employee> <Name>Sarah</Name> <