aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/ListBox.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-10-05 12:08:56 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-10-05 12:08:57 +0200
commit4c15030701964aee1c1dc908d6fa4dcdbec16a12 (patch)
treeabc69bdd9cd0713d795a924d329b4466e31bbac6 /src/GraphicObjects/ListBox.cs
parent8dcac53903c37878d54d59066eb7f80da1d62bc7 (diff)
threaded combo, Monodevelop addin improve
Diffstat (limited to 'src/GraphicObjects/ListBox.cs')
-rw-r--r--src/GraphicObjects/ListBox.cs76
1 files changed, 55 insertions, 21 deletions
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index 9435ffbe..9f408b5a 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -26,6 +26,8 @@ using System.ComponentModel;
using System.IO;
using System.Diagnostics;
using System.Xml;
+using System.Collections.Generic;
+using System.Threading;
namespace go
{
@@ -84,33 +86,65 @@ namespace go
if (data == null)
return;
- #if DEBUG_LOAD_TIME
- Stopwatch loadingTime = new Stopwatch ();
- loadingTime.Start ();
- #endif
+ pendingChildrenAddition = new Queue<GraphicObject> ();
+ threadedLoadingFinished = false;
- MemoryStream ms = new MemoryStream ();
- using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
+ Thread t = new Thread (loadingThread);
+ t.Start ();
+
+ }
+ }
+
+ internal void CheckPendingChildrenAddition()
+ {
+ if (pendingChildrenAddition == null)
+ return;
+ lock (pendingChildrenAddition) {
+ if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50)
+ return;
+ while (pendingChildrenAddition.Count > 0)
+ _list.addChild (pendingChildrenAddition.Dequeue ());
+ }
+ }
+
+ volatile Queue<GraphicObject> pendingChildrenAddition;
+ volatile bool threadedLoadingFinished = false;
+
+ void loadingThread()
+ {
+ #if DEBUG_LOAD_TIME
+ Stopwatch loadingTime = new Stopwatch ();
+ loadingTime.Start ();
+ #endif
+
+ MemoryStream ms = new MemoryStream ();
+ lock (ItemTemplate) {
+ using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
stream.CopyTo (ms);
-
- Type t = Interface.GetTopContainerOfGOMLStream (ms);
+ }
- foreach (var item in data) {
- ms.Seek(0,SeekOrigin.Begin);
- GraphicObject g = Interface.Load (ms, t, item);
- g.MouseClick += itemClick;
- _list.addChild(g);
- }
+ Type t = Interface.GetTopContainerOfGOMLStream (ms);
- ms.Dispose ();
+ foreach (var item in data) {
+ ms.Seek(0,SeekOrigin.Begin);
+ GraphicObject g = Interface.Load (ms, t, item);
+ g.MouseClick += itemClick;
- #if DEBUG_LOAD_TIME
- loadingTime.Stop ();
- Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
- loadingTime.ElapsedTicks,
- loadingTime.ElapsedMilliseconds, this.ToString());
- #endif
+ lock (pendingChildrenAddition) {
+ pendingChildrenAddition.Enqueue (g);
+ }
}
+
+ ms.Dispose ();
+
+ threadedLoadingFinished = true;
+
+ #if DEBUG_LOAD_TIME
+ loadingTime.Stop ();
+ Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
+ loadingTime.ElapsedTicks,
+ loadingTime.ElapsedMilliseconds, this.ToString());
+ #endif
}
void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){