aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/ListBox.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-08-03 04:27:17 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2016-08-03 04:27:17 +0200
commit51e7ed159c72331bf1003b3fc88ee68753724a2a (patch)
tree96b906e9cc8fdeb47329a6eb889d0e2a2442c71a /src/GraphicObjects/ListBox.cs
parentb0452394b2173f95f0f29009fa524c82b628d5f5 (diff)
debug sync threading
Diffstat (limited to 'src/GraphicObjects/ListBox.cs')
-rw-r--r--src/GraphicObjects/ListBox.cs31
1 files 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);