From: Jean-Philippe Bruyère Date: Mon, 27 Jan 2020 12:03:11 +0000 (+0100) Subject: remove thread.abord (not supported by netcore) and add Mutexes release before asking... X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=199019201a399a93acaf90b6ccb4d52cede6b799;p=jp%2Fcrow.git remove thread.abord (not supported by netcore) and add Mutexes release before asking cancel on a ui thread --- diff --git a/Crow/Crow.csproj b/Crow/Crow.csproj index b162e616..85b4ae96 100644 --- a/Crow/Crow.csproj +++ b/Crow/Crow.csproj @@ -18,7 +18,7 @@ False https://github.com/jpbruyere/Crow/wiki https://opensource.org/licenses/MIT - https://jpbruyere.github.io/Crow/images/crow.png + crow.png Copyright 2013-2019 @@ -26,7 +26,7 @@ True true - $(NoWarn);1591 + $(NoWarn);1591;1587;1570;1572;1573;1574 DESIGN_MODE @@ -44,7 +44,8 @@ - + + Crow.%(Filename).template @@ -52,4 +53,4 @@ - \ No newline at end of file + diff --git a/Crow/src/CrowThread.cs b/Crow/src/CrowThread.cs index c0121bec..01558753 100644 --- a/Crow/src/CrowThread.cs +++ b/Crow/src/CrowThread.cs @@ -1,28 +1,6 @@ -// -// CrowThread.cs +// Copyright (c) 2013-2020 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2013-2017 Jean-Philippe Bruyère -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Threading; @@ -55,8 +33,8 @@ namespace Crow public void Cancel(){ if (thread.IsAlive & !cancelRequested){ cancelRequested = true; - Thread.Sleep (1); - thread.Abort (); + while (thread.IsAlive) + Thread.Sleep (1); thread.Join (); } lock (Host.IFace.CrowThreads) diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index ee4f04c6..9a94d703 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -474,11 +474,13 @@ namespace Crow /// path of the iml file to load public Widget Load (string path) { - lock (UpdateMutex) { - Widget tmp = CreateInstance (path); - AddWidget (tmp); - return tmp; - } + Monitor.Enter (UpdateMutex); + + Widget tmp = CreateInstance (path); + AddWidget (tmp); + + Monitor.Exit (UpdateMutex); + return tmp; } /// /// Create an instance of a GraphicObject linked to this interface but not added to the GraphicTree diff --git a/Crow/src/Widgets/TemplatedGroup.cs b/Crow/src/Widgets/TemplatedGroup.cs index 9546174e..a4a955ff 100644 --- a/Crow/src/Widgets/TemplatedGroup.cs +++ b/Crow/src/Widgets/TemplatedGroup.cs @@ -361,8 +361,24 @@ namespace Crow { // } // } void cancelLoadingThread(){ - if (loadingThread != null) - loadingThread.Cancel (); + if (loadingThread == null) + return; + + bool updateMx = Monitor.IsEntered (IFace.UpdateMutex); + bool layoutMx = Monitor.IsEntered (IFace.LayoutMutex); + + if (layoutMx) + Monitor.Exit (IFace.LayoutMutex); + if (updateMx) + Monitor.Exit (IFace.UpdateMutex); + + loadingThread.Cancel (); + + if (layoutMx) + Monitor.Enter (IFace.LayoutMutex); + if (updateMx) + Monitor.Enter (IFace.UpdateMutex); + } void loadPage(IEnumerable _data, Group page, string _dataTest) { @@ -519,8 +535,8 @@ namespace Crow { protected override void Dispose (bool disposing) { - if (disposing && loadingThread != null) - loadingThread.Cancel (); + if (disposing) + cancelLoadingThread (); base.Dispose (disposing); } diff --git a/clean.sh b/clean.sh new file mode 100755 index 00000000..a5567477 --- /dev/null +++ b/clean.sh @@ -0,0 +1,2 @@ +#!/bin/bash +rm -fr build && find . -iname bin -o -iname obj -o -iname packages | xargs rm -rf