Questions tagged [parallel.invoke]

19 questions
25
votes
4 answers

Are Parallel.Invoke and Parallel.ForEach essentially the same thing?

And by "same thing" I mean do these two operations basically do the same work, and it just boils down to which one is more convenient to call based on what you have to work with? (i.e. a list of delegates or a list of things to iterate over)? I've…
4
votes
1 answer

Parallel.Invoke and thread invocation - Clarification?

I have this code which creates a deadlock : void Main() { ClassTest test = new ClassTest(); lock(test) { Task t1 = new Task(() => test.DoWorkUsingThisLock(1)); t1.Start(); t1.Wait(); } } public class…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
3
votes
1 answer

Is Parallel.Invoke same as calling multiple Task.Run's?

Task.Run: Queues the specified work to run on the ThreadPool and returns a task or Task handle for that work. Parallel.Invoke: Executes each of the provided actions, possibly in parallel. Effectively they spin up a new thread from the…
variable
  • 8,262
  • 9
  • 95
  • 215
3
votes
1 answer

How can I have log4net create a separate log file for each Action in a Parallel.Invoke?

I have a series of Action that I want to execute in parallel using Parallel.Invoke. But for each Action I want to have a separate log file created by log4net. In my log4net configuration file I have added this:
1
vote
4 answers

When is Parallel.Invoke useful?

I'm just diving into learning about the Parallel class in the 4.0 Framework and am trying to understand when it would be useful. At first after reviewing some of the documentation I tried to execute two loops, one using Parallel.Invoke and one…
Ta01
  • 31,040
  • 13
  • 70
  • 99
1
vote
1 answer

Cancel tasks in Parallel.Invoke

As I understand it, all three static methods in Parallel (For, ForEach and Invoke) create tasks in the background. You can stop creating these tasks with cancel a token inside ParallelOptions. I made two simple examples. In the first uses the For…
user17737068
1
vote
3 answers

Add and remove Parallel.Invoke actions during runtime

I'm using Parallel.Invoke to run certain methods simultaneously and collect the results when all methods are finished. PROBLEM As you can see on the "horrible code" section, the list of actions is hardcoded to three elements, and will be totally…
1
vote
1 answer

Updating different properties of same object in Parallel.Invoke is thread-safe?

I'm working with a class which contains complex properties. Each of these properties are computed through different methods. I'm using Parallel.Invoke to update different properties of the same object. Will this cause any issue to the object ? //…
1
vote
0 answers

Is Parallel.Invoke() always using it's calling thread?

If I have the following program public class MainClass { public static void Main () { Console.WriteLine($"Main [{Thread.CurrentThread.ManagedThreadId}]"); Parallel.Invoke( () => Foo(), () => Bar()…
Ackdari
  • 3,222
  • 1
  • 16
  • 33
1
vote
1 answer

Parallel.Invoke vs Parallel.Foreach for running parallel process on large list

I have C# list which contains around 8000 items (file paths). I want to run a method on all of these items in parallel. For this i have below 2 options: 1) Manually divide list into small-small chunks (say of 500 size each) and create array of…
Gurmeet
  • 3,094
  • 4
  • 19
  • 43
1
vote
3 answers

Parallel invoking with conditionally

I have a scenario where I would like to invoke functions but want them to be invoke conditionally. So in the below code only function 2 and 3 will be invoked. However, the Action part doesnt return a value but in my case I want to store the return…
Kar
  • 105
  • 11
1
vote
0 answers

Performance of Informix SQL connection for multiple commands when using Parallel.Invoke

As far as I know, there are two ways for the SQL connection handling when executing multiple commands in parallel using the Threading.Tasks.Parallel.Invoke approach. The first method is to define a common SQL connection which is shared between all…
1
vote
2 answers

How to add methods dynamically inside a parallel.invoke

Given below is the sample code. string[] str = new string[10]; str[0] = "A"; str[1] = "B"; .... and so on. Parallel.Invoke(() => { foreach(string temp in str) …
0
votes
0 answers

Parallelization on Android Emulator - Pixel 5 API 33

In my .NET MAUI App I was using an await Task.Run(() => ...); to do a Branch and Bound Calculation. Within that there is also an Task.Run(() => ...);. So far it was running good, but not fast enough for what I was used to. Then I started to optimize…
OXO
  • 391
  • 1
  • 8
0
votes
1 answer

Can we call methods (with parameters) in Parallel in Xamarin iOS?

I have an Xamarin App using Parallel.Invoke which is working fine on Android. Parallel.Invoke ( () => AddOrReplaceWordsAndDefinitions(wordsAndDefinitions, conn), () => AddOrReplaceWords(wordsAndDefinitions, conn) ); However I'm now trying to…
Syl.H
  • 221
  • 2
  • 10
1
2