c# Parallel Processing throws NullReference Exception in task resource -


I try to parallel the processing of my data. That's why I start a processor object for each parallel function with the local parallel parameter, it works fine for every task to run first, but on the second iteration, I always get a NullReferenceException.

The document is called parallel to the local Init parameter. ForEach:

  localInit: // function delegation which / gives the initial state of local data for each job   

So, what do I do?

  Processor Getmap Processor () {Processor Processor = New Processor (); // some initial return processor; } Zero similarities () {IEnumerable & lt; MyClass & gt; MyData = ...; Parallel.ForEach (myData, new parallelOptions {MaxDegreeOfParallelism = 8}, GetMyProcessor, (data, state, processor) => processor.dozing (); // <----- null reference exception}, (item ) = & Gt; {} // nothing for the moment); }    

I tried to do this and it works fine for me Can run it and tell me if you're still getting an exception?

  Fixed zero main (string [] args) {program p = new program (); P.ParallelThings (); } Processor GetMyProcessor () {Processor Processor = New Processor (); // some initial return processor; } Zero similarities () {IEnumerable & lt; MyClass & gt; My friendship (), new MyClass (), new MyClass (), new MyClass (), new MyClass (), new MyClass (), MyData = new list & lt; MyClass & gt; (New MyClass), New MyClass (), New MyClass () New MyClass (), New Maccaldle (), New Macclass (), New Maccaldle (), New Macclass (), New MacCalus (), New MacCal ), New Macchel ()}; Parallel.ForEach, new parallel option {MaxDegreeOfParallelism = 8}, GetMyProcessor, (data, state, processor) = & gt; {// console.writeLine (DateTime.Now); Return processor.DosSomething (); // & Lt; - --- no exceptions}, (object) => gt; {} / do nothing for the moment); }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -