Search code examples
c#parallel.foreach.net-standard-1.4

Using Parallel.ForEach in a class library


A simple Parallel.ForEach do not want to be in the Library Class

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace UtilyTools
{
    public class Why
    {
        public void gluk()
        {
            var intList= new List<int> { 1, 2, 3};
            int notMatter=0;
            Parallel.ForEach(intList, (item) => notMatter+= item);
        }
    }
    // [...]

Gives me the old:

CS0103 C# The name Parallel does not exist in the current context

Project.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup>
</Project>

As requested a screen shoot of the error: nb: using are not underline in red.

Picture of the issue


Solution

  • Since you're using .NetStandard library and not the .NetFramework you have to include System.Threading.Tasks.Parallel as a dependency in to your project.