diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-10-05 12:08:56 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-10-05 12:08:57 +0200 |
| commit | 4c15030701964aee1c1dc908d6fa4dcdbec16a12 (patch) | |
| tree | abc69bdd9cd0713d795a924d329b4466e31bbac6 /src/GraphicObjects/Combobox.cs | |
| parent | 8dcac53903c37878d54d59066eb7f80da1d62bc7 (diff) | |
threaded combo, Monodevelop addin improve
Diffstat (limited to 'src/GraphicObjects/Combobox.cs')
| -rw-r--r-- | src/GraphicObjects/Combobox.cs | 86 |
1 files changed, 61 insertions, 25 deletions
diff --git a/src/GraphicObjects/Combobox.cs b/src/GraphicObjects/Combobox.cs index c9781f71..02040570 100644 --- a/src/GraphicObjects/Combobox.cs +++ b/src/GraphicObjects/Combobox.cs @@ -16,6 +16,7 @@ using System.ComponentModel; using System.Xml;
using System.IO;
using System.Collections;
+using System.Threading;
namespace go
{
@@ -146,40 +147,75 @@ namespace go _list.registerForGraphicUpdate ();
if (data == null)
return;
+ if (SelectedIndex < 0)
+ return;
- #if DEBUG_LOAD_TIME
- Stopwatch loadingTime = new Stopwatch ();
- loadingTime.Start ();
- #endif
+ //force raise of changes
+ SelectedIndex = SelectedIndex;
- MemoryStream ms = new MemoryStream ();
- using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
- stream.CopyTo (ms);
+ pendingChildrenAddition = new Queue<GraphicObject> ();
+ threadedLoadingFinished = false;
- Type t = Interface.GetTopContainerOfGOMLStream (ms);
+ Thread t = new Thread (loadingThread);
+ t.Start ();
- foreach (var item in data) {
- ms.Seek(0,SeekOrigin.Begin);
- GraphicObject g = Interface.Load (ms, t, item);
- g.MouseClick += itemClick;
- _list.addChild(g);
- }
+ }
+ }
+ public override void UpdateLayout (LayoutingType layoutType)
+ {
+ CheckPendingChildrenAddition ();
+ base.UpdateLayout (layoutType);
+ }
+ internal void CheckPendingChildrenAddition()
+ {
+ if (pendingChildrenAddition == null)
+ return;
+ lock (pendingChildrenAddition) {
+ if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50)
+ return;
+ while (pendingChildrenAddition.Count > 0)
+ _list.addChild (pendingChildrenAddition.Dequeue ());
+ }
+ }
- ms.Dispose ();
+ volatile Queue<GraphicObject> pendingChildrenAddition;
+ volatile bool threadedLoadingFinished = false;
- if (SelectedIndex < 0)
- return;
+ void loadingThread()
+ {
+ #if DEBUG_LOAD_TIME
+ Stopwatch loadingTime = new Stopwatch ();
+ loadingTime.Start ();
+ #endif
- //force raise of changes
- SelectedIndex = SelectedIndex;
+ MemoryStream ms = new MemoryStream ();
+ lock (ItemTemplate) {
+ using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
+ stream.CopyTo (ms);
+ }
+
+ Type t = Interface.GetTopContainerOfGOMLStream (ms);
- #if DEBUG_LOAD_TIME
- loadingTime.Stop ();
- Debug.WriteLine("Listbox Loading: {0} ticks \t, {1} ms",
- loadingTime.ElapsedTicks,
- loadingTime.ElapsedMilliseconds);
- #endif
+ foreach (var item in data) {
+ ms.Seek(0,SeekOrigin.Begin);
+ GraphicObject g = Interface.Load (ms, t, item);
+ g.MouseClick += itemClick;
+
+ 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
}
public GraphicObject Overlay {
get { return _overlay; }
|