Once more about changing of ProgressBar in WinForm from Parallel

时间:2016-04-15 11:13:18

标签: c# winforms

It has been much already written about. But seems to me not clear.

I need to modify ProgressBar in WinForm according the calculus beeing provided in parallel flow. Code is below:

        namespace my_space
        {
          class myLongCalculus
          {
            static int iCount;

            doSomeLongJob()
            {
              cycle1
              {
                cycle2
                {
                  iCount += number
        //      Here should be ProgressBar in Form1 modified !
                }
              }
           }

           public class Form1 : Form
           {
             public Form1()
             {
               int iMax = 6;

               ProgressBar pb = new ProgressBar();
               pb.Max = Maximum;

               for(int i=0, i<iMax; i++)
                 listOfObjects.Add(new myLongCalculus(i));

               Parallel.For(0, iMax, i =>
               {
                 listOfObjects[i].doSomeLongJob();
               });
             }
            }

         }

I tried various tricks threads, invoke, but with the same result: after the first changing of ProgressBar parallel flow terminates and returns to calling program.

Any ideas will be appreciated

0 个答案:

没有答案