From 51e7ed159c72331bf1003b3fc88ee68753724a2a Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Wed, 3 Aug 2016 04:27:17 +0200 Subject: [PATCH] debug sync threading --- src/GraphicObjects/ListBox.cs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 6f433678..0543a0b2 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -47,7 +47,7 @@ namespace Crow IList data; int _selectedIndex; string _itemTemplate; - int itemPerPage = 100; + int itemPerPage = 20; MemoryStream templateStream = null; Type templateBaseType = null; Thread loadingThread = null; @@ -67,7 +67,8 @@ namespace Crow NotifyValueChanged ("Data", data); - _list.ClearChildren (); + lock (Interface.CurrentInterface.UpdateMutex) + _list.ClearChildren (); if (_gsList.Orientation == Orientation.Horizontal) _gsList.Width = -1; else @@ -131,15 +132,24 @@ namespace Crow _gsList = _list as GenericStack; } #endregion - void loading(){ - for (int i = 1; i <= (data.Count / itemPerPage)+1; i++) + void loading(){ + lock (Interface.CurrentInterface.UpdateMutex) { + templateStream = new MemoryStream (); + using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) + stream.CopyTo (templateStream); + templateBaseType = Interface.GetTopContainerOfXMLStream (templateStream); + } + for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) { + if (cancelLoading) + return; loadPage (i); + } } void cancelLoadingThread(){ if (loadingThread == null) return; if (!loadingThread.IsAlive) - return; + return; cancelLoading = true; loadingThread.Join (); cancelLoading = false; @@ -151,15 +161,6 @@ namespace Crow loadingTime.Start (); #endif - if (templateStream == null) { - templateStream = new MemoryStream (); - lock (ItemTemplate) { - using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) - stream.CopyTo (templateStream); - } - templateBaseType = Interface.GetTopContainerOfXMLStream (templateStream); - } - Group page = _list.Clone () as Group; page.Name = "page" + pageNum; @@ -177,7 +178,7 @@ namespace Crow for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) { if (i >= data.Count) break; - if (cancelLoading == true) + if (cancelLoading) return; templateStream.Seek (0, SeekOrigin.Begin); GraphicObject g = Interface.Load (templateStream, templateBaseType); -- 2.47.3