Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / WindowsBase / System.Windows.Threading / Dispatcher.cs
index 178e22db1a800455a1a8e2d5d39f326f19564193..a28f7a29d0d3801f1b811d81e3dd1533a2c84a17 100644 (file)
@@ -398,6 +398,11 @@ namespace System.Windows.Threading {
                                                                DispatcherOperation task;
                                                                
                                                                lock (q){
+                                                                       // if we are done with this queue, leave.
+                                                                       if (q.Count == 0){
+                                                                               queue_bits &= ~current_bit;
+                                                                               break;
+                                                                       }
                                                                        task = (DispatcherOperation) q.Dequeue ();
                                                                }
                                                                
@@ -418,20 +423,15 @@ namespace System.Windows.Threading {
                                                                        PerformShutdown ();
                                                                        return;
                                                                }
-                                                               
-                                                               // if we are done with this queue, leave.
-                                                               lock (q){
-                                                                       if (q.Count == 0){
-                                                                               queue_bits &= ~(1 << i);
-                                                                               break;
-                                                                       }
-                                                               }
 
                                                                //
                                                                // If a higher-priority task comes in, go do that
                                                                //
                                                                if (current_bit < (queue_bits & ~current_bit))
+                                                               {
+                                                                       i = TOP_PRIO + 1; // for-loop decreases by one
                                                                        break;
+                                                               }
                                                        } while (true);
                                                }
                                        }