.NET 2.0 中的等效任务是什么?

What is the equivalent task in .NET 2.0?

提问人:김영호 提问时间:8/8/2019 最后编辑:halfer김영호 更新时间:8/9/2019 访问量:107

问:

我知道 .NET 2.0 现在真的很旧,但我有我想在 .NET 2.0 下编译的代码。不幸的是,源代码使用 .NET 4.0 System.Threading.Tasks

代码如下:

 public override string Encode(byte[] data)
 {
     if (data == null || data.Length == 0)
         return "";

     int mainBitsLength = (data.Length * 8 / BlockBitsCount) * BlockBitsCount;
     int tailBitsLength = data.Length * 8 - mainBitsLength;
     int totalBitsLength = mainBitsLength + tailBitsLength;
     int mainCharsCount = mainBitsLength * BlockCharsCount / BlockBitsCount;
     int tailCharsCount = (tailBitsLength * BlockCharsCount + BlockBitsCount - 1) / BlockBitsCount;
     int totalCharsCount = mainCharsCount + tailCharsCount;
     int iterationCount = mainCharsCount / BlockCharsCount;

     var result = new char[totalCharsCount];

     if (!Parallel)
         EncodeBlock(data, result, 0, iterationCount);
     else {
         int processorCount = Math.Min(iterationCount, Environment.ProcessorCount);
         System.Threading.Tasks.Parallel.For(0, processorCount, i =>
            {
                int beginInd = i * iterationCount / processorCount;
                int endInd = (i + 1) * iterationCount / processorCount;
                EncodeBlock(data, result, beginInd, endInd);
            });
     }

     if (tailBitsLength != 0)
     {
         ulong bits = GetBits64(data, mainBitsLength, tailBitsLength);
         BitsToChars(result, mainCharsCount, tailCharsCount, bits);
     }

     return new string(result);
 }

我不是线程方面的专家。有人可以在 .NET 2.0 中重现相同的行为并给出明确的解释吗?

C# net-2.0

评论

0赞 dymanoid 8/8/2019
手动使用和启动胎面。System.Threading.Thread
0赞 Bill Tür stands with Ukraine 8/8/2019
.NET 2.0 中等效任务的可能重复项
0赞 ℍ ℍ 8/8/2019
Jusrt 设置为 false。删除 nocompiling 代码。Parallel

答: 暂无答案