Verrou non bloquant

This commit is contained in:
tzim 2013-11-23 12:05:59 +00:00
parent 9c41df3665
commit b5fc4fda64
2 changed files with 40 additions and 32 deletions

View file

@ -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);
}
}
}

View file

@ -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<Circuit> circuits = new List<Circuit> (effetsEnCours.Keys);
lock (this) {
if(effetsEnCours.Count>0)
{
List<Circuit> circuits = new List<Circuit> (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);
}
}
}