aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/Wrapper.cs
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-02-21 16:11:30 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-02-21 16:11:30 +0100
commit05e7cd5133826afd42d215e08c4874ee48ed49be (patch)
tree2f449777278cc8b4805a4e80d7ee81b3863bc4a1 /src/GraphicObjects/Wrapper.cs
parent30b49efa1763ebdfe82f9d69e0e7bafcdd3b25a8 (diff)
implement ReaderWritelLockSlim to resolve threading issues
Diffstat (limited to 'src/GraphicObjects/Wrapper.cs')
-rw-r--r--src/GraphicObjects/Wrapper.cs80
1 files changed, 46 insertions, 34 deletions
diff --git a/src/GraphicObjects/Wrapper.cs b/src/GraphicObjects/Wrapper.cs
index e56d9332..4fff17ff 100644
--- a/src/GraphicObjects/Wrapper.cs
+++ b/src/GraphicObjects/Wrapper.cs
@@ -131,26 +131,32 @@ namespace Crow
else {
int dy = 0;
int largestChild = 0;
- lock (Children) {
- foreach (GraphicObject c in Children) {
- if (!c.Visible)
- continue;
- if (c.Height.Units == Unit.Percent &&
- c.RegisteredLayoutings.HasFlag (LayoutingType.Height))
- return -1;
- if (dy + c.Slot.Height > ClientRectangle.Height) {
- dy = 0;
- tmp += largestChild + Spacing;
- largestChild = c.Slot.Width;
- } else if (largestChild < c.Slot.Width)
- largestChild = c.Slot.Width;
- dy += c.Slot.Height + Spacing;
+ childrenRWLock.EnterReadLock();
+
+ foreach (GraphicObject c in Children) {
+ if (!c.Visible)
+ continue;
+ if (c.Height.Units == Unit.Percent &&
+ c.RegisteredLayoutings.HasFlag (LayoutingType.Height)) {
+ childrenRWLock.ExitReadLock();
+ return -1;
}
- if (dy == 0)
- tmp -= Spacing;
- return tmp + largestChild + 2 * Margin;
+ if (dy + c.Slot.Height > ClientRectangle.Height) {
+ dy = 0;
+ tmp += largestChild + Spacing;
+ largestChild = c.Slot.Width;
+ } else if (largestChild < c.Slot.Width)
+ largestChild = c.Slot.Width;
+
+ dy += c.Slot.Height + Spacing;
}
+
+ childrenRWLock.ExitReadLock ();
+
+ if (dy == 0)
+ tmp -= Spacing;
+ return tmp + largestChild + 2 * Margin;
}
} else if (Orientation == Orientation.Horizontal) {
Height = Measure.Stretched;
@@ -160,26 +166,32 @@ namespace Crow
else {
int dx = 0;
int tallestChild = 0;
- lock (Children) {
- foreach (GraphicObject c in Children) {
- if (!c.Visible)
- continue;
- if (c.Width.Units == Unit.Percent &&
- c.RegisteredLayoutings.HasFlag (LayoutingType.Width))
- return -1;
- if (dx + c.Slot.Width > ClientRectangle.Width) {
- dx = 0;
- tmp += tallestChild + Spacing;
- tallestChild = c.Slot.Height;
- } else if (tallestChild < c.Slot.Height)
- tallestChild = c.Slot.Height;
- dx += c.Slot.Width + Spacing;
+ childrenRWLock.EnterReadLock();
+
+ foreach (GraphicObject c in Children) {
+ if (!c.Visible)
+ continue;
+ if (c.Width.Units == Unit.Percent &&
+ c.RegisteredLayoutings.HasFlag (LayoutingType.Width)) {
+ childrenRWLock.ExitReadLock();
+ return -1;
}
- if (dx == 0)
- tmp -= Spacing;
- return tmp + tallestChild + 2 * Margin;
+ if (dx + c.Slot.Width > ClientRectangle.Width) {
+ dx = 0;
+ tmp += tallestChild + Spacing;
+ tallestChild = c.Slot.Height;
+ } else if (tallestChild < c.Slot.Height)
+ tallestChild = c.Slot.Height;
+
+ dx += c.Slot.Width + Spacing;
}
+
+ childrenRWLock.ExitReadLock();
+
+ if (dx == 0)
+ tmp -= Spacing;
+ return tmp + tallestChild + 2 * Margin;
}
}