System.InvalidOperationException with tasks in C#

后端 未结 1 1488
离开以前
离开以前 2021-01-27 07:04

I am trying to make my code faster by using tasks (Parallel.foreach). Here is my updated code:

int intImageW, intImageH;
Bitmap bmpDest = new Bitmap(1, 1);
DateT         


        
1条回答
  •  迷失自我
    2021-01-27 07:19

    All your Tasks access to the same shared Bitmap bmpDest.

    Move the definition of it to Parallel.ForEach block so that every task can use its own Bitmap..

    Parallel.ForEach(strarrFileList, strJPGImagePath =>
    {
         Bitmap bmpDest = new Bitmap(1, 1);
         ........
    });
    

    0 讨论(0)
提交回复
热议问题