From b5fc4fda64e75aa07e799059ace5e55be1b61171 Mon Sep 17 00:00:00 2001 From: tzim Date: Sat, 23 Nov 2013 12:05:59 +0000 Subject: [PATCH] Verrou non bloquant --- DMX-2.0/SequenceurLineaire.cs | 37 ++++++++++++++++++++--------------- DMX-2.0/SequenceurMacro.cs | 35 ++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/DMX-2.0/SequenceurLineaire.cs b/DMX-2.0/SequenceurLineaire.cs index e6d2bcc..72e661f 100644 --- a/DMX-2.0/SequenceurLineaire.cs +++ b/DMX-2.0/SequenceurLineaire.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Threading; namespace DMX2 { @@ -321,27 +322,31 @@ namespace DMX2 public override void Tick (TimeSpan time) { - if (paused) return; + if (paused) + return; timeStamp += time; - lock(this) { - if (enTransition) { - if (timeStamp < tempsTransition) { - double progression = timeStamp.TotalMilliseconds / tempsTransition.TotalMilliseconds; - foreach (Circuit c in circuitsSeq) { - if (valeurscourantes [c] != effetcourrant [c] && !valeurschangees.ContainsKey (c)) { - valeurscourantes [c] = (int)(progression * (effetcourrant [c] - valeursinitiales [c]) + valeursinitiales [c]); + if (Monitor.TryEnter (this)) + try { + if (enTransition) { + if (timeStamp < tempsTransition) { + double progression = timeStamp.TotalMilliseconds / tempsTransition.TotalMilliseconds; + foreach (Circuit c in circuitsSeq) { + if (valeurscourantes [c] != effetcourrant [c] && !valeurschangees.ContainsKey (c)) { + valeurscourantes [c] = (int)(progression * (effetcourrant [c] - valeursinitiales [c]) + valeursinitiales [c]); + } } + } else { + FinDeTransition (); } - } else { - FinDeTransition (); } + if (effetcourrant.Duree != TimeSpan.Zero && timeStamp >= effetcourrant.Duree) { + int index = effets.IndexOf (effetcourrant) + 1; + if (index < effets.Count) + ChangeEffetCourrant (index); + } + } finally { + Monitor.Exit (this); } - if (effetcourrant.Duree != TimeSpan.Zero && timeStamp >= effetcourrant.Duree) { - int index = effets.IndexOf (effetcourrant) + 1; - if (index < effets.Count) - ChangeEffetCourrant (index); - } - } } diff --git a/DMX-2.0/SequenceurMacro.cs b/DMX-2.0/SequenceurMacro.cs index 7b2774f..ee2fe31 100644 --- a/DMX-2.0/SequenceurMacro.cs +++ b/DMX-2.0/SequenceurMacro.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Xml; using System.Collections.ObjectModel; +using System.Threading; namespace DMX2 { @@ -311,26 +312,28 @@ namespace DMX2 return; timeStamp += time; + if (Monitor.TryEnter (this)) { + try { + if (effetsEnCours.Count > 0) { + List circuits = new List (effetsEnCours.Keys); - lock (this) { - if(effetsEnCours.Count>0) - { - List circuits = new List (effetsEnCours.Keys); - - foreach (Circuit c in circuits) { - if (effetsEnCours [c].Incremente (time)) { - valeurscourantes [c] = effetsEnCours [c].ValeurFinale; - effetsEnCours.Remove (c); - } else { - valeurscourantes [c] = effetsEnCours [c].ValeurCourante (); + foreach (Circuit c in circuits) { + if (effetsEnCours [c].Incremente (time)) { + valeurscourantes [c] = effetsEnCours [c].ValeurFinale; + effetsEnCours.Remove (c); + } else { + valeurscourantes [c] = effetsEnCours [c].ValeurCourante (); + } } } - } - } - if (topPresent) { - if (timeStamp > topSuivant){ - LigneSuivante(); + if (topPresent) { + if (timeStamp > topSuivant) { + LigneSuivante (); + } + } + } finally { + Monitor.Exit (this); } } }