From 4bd87cb39b82ff5576d08c3a8bd100792714d409 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 21 Aug 2019 16:49:43 +0200 Subject: [PATCH] thread lock seems solved for fileviewer --- Crow/Crow.csproj | 2 +- Crow/src/CrowThread.cs | 2 ++ Crow/src/GraphicObjects/TemplatedGroup.cs | 16 ++++++++++++---- Crow/src/GraphicObjects/Widget.cs | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Crow/Crow.csproj b/Crow/Crow.csproj index 857a24e9..e6ecc933 100644 --- a/Crow/Crow.csproj +++ b/Crow/Crow.csproj @@ -1,7 +1,7 @@ - net461;net471;netstandard2.0 + net461;netstandard2.0 Crow 0.8.3.2 diff --git a/Crow/src/CrowThread.cs b/Crow/src/CrowThread.cs index 5c5ceef0..c0121bec 100644 --- a/Crow/src/CrowThread.cs +++ b/Crow/src/CrowThread.cs @@ -55,6 +55,8 @@ namespace Crow public void Cancel(){ if (thread.IsAlive & !cancelRequested){ cancelRequested = true; + Thread.Sleep (1); + thread.Abort (); thread.Join (); } lock (Host.IFace.CrowThreads) diff --git a/Crow/src/GraphicObjects/TemplatedGroup.cs b/Crow/src/GraphicObjects/TemplatedGroup.cs index cb57a721..3556eaf0 100644 --- a/Crow/src/GraphicObjects/TemplatedGroup.cs +++ b/Crow/src/GraphicObjects/TemplatedGroup.cs @@ -29,6 +29,7 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Threading; using Crow.IML; namespace Crow { @@ -205,7 +206,7 @@ namespace Crow { NotifyValueChanged ("Data", data); - //lock (CurrentInterface.LayoutMutex) + lock (IFace.LayoutMutex) ClearItems (); if (data == null) @@ -337,7 +338,14 @@ namespace Crow { /// Items loading thread /// void loading(){ - loadPage (data, items, dataTest); + try { + loadPage (data, items, dataTest); + } catch (Exception ex) { + if (Monitor.IsEntered (IFace.LayoutMutex)) + Monitor.Exit (IFace.LayoutMutex); + Console.WriteLine ("loading thread aborted"); + } + } // //if (!ItemTemplates.ContainsKey ("default")) // // ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate); @@ -441,7 +449,7 @@ namespace Crow { iTemp = ItemTemplates ["default"]; } - lock (IFace.LayoutMutex) { + Monitor.Enter (IFace.LayoutMutex); g = iTemp.CreateInstance(); #if DESIGN_MODE g.design_isTGItem = true; @@ -450,7 +458,7 @@ namespace Crow { // if (isPaged) g.LogicalParent = this; g.MouseClick += itemClick; - } + Monitor.Exit (IFace.LayoutMutex); if (iTemp.Expand != null && g is Expandable) { Expandable e = g as Expandable; diff --git a/Crow/src/GraphicObjects/Widget.cs b/Crow/src/GraphicObjects/Widget.cs index 663cb26e..d85ddfaa 100644 --- a/Crow/src/GraphicObjects/Widget.cs +++ b/Crow/src/GraphicObjects/Widget.cs @@ -1007,7 +1007,7 @@ namespace Crow #if DEBUG_LOG DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GOLockLayouting, this); #endif - lock (IFace.LayoutMutex) { + lock (IFace.UpdateMutex) { OnDataSourceChanged (this, dse); NotifyValueChanged ("DataSource", DataSource); } -- 2.47.3