Throw an an exception when Break and Stop are used in combination.
authorJérémie Laval <jeremie.laval@gmail.com>
Fri, 12 Nov 2010 14:02:41 +0000 (14:02 +0000)
committerJérémie Laval <jeremie.laval@gmail.com>
Fri, 12 Nov 2010 14:02:41 +0000 (14:02 +0000)
mcs/class/corlib/System.Threading.Tasks/ParallelLoopState.cs

index d957e086e9492607714b709e0379b22b17ee4a1a..adaa7f97a54dca396d2716db876fc450a0527895 100644 (file)
@@ -76,6 +76,9 @@ namespace System.Threading.Tasks
                
                public void Break ()
                {
+                       if (extInfos.IsStopped)
+                               throw new InvalidOperationException ("The Stop method was previously called. Break and Stop may not be used in combination by iterations of the same loop.");
+
                        bool result = extInfos.IsBroken.Exchange (true);
                        if (!result)
                                extInfos.LowestBreakIteration = CurrentIteration;
@@ -83,6 +86,8 @@ namespace System.Threading.Tasks
                
                public void Stop ()
                {
+                       if (extInfos.IsBroken.Value)
+                               throw new InvalidOperationException ("The Break method was previously called. Break and Stop may not be used in combination by iterations of the same loop.");
                        extInfos.IsStopped = true;
                }
        }