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.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Threading;
namespace DMX2 namespace DMX2
{ {
@ -321,9 +322,11 @@ namespace DMX2
public override void Tick (TimeSpan time) public override void Tick (TimeSpan time)
{ {
if (paused) return; if (paused)
return;
timeStamp += time; timeStamp += time;
lock(this) { if (Monitor.TryEnter (this))
try {
if (enTransition) { if (enTransition) {
if (timeStamp < tempsTransition) { if (timeStamp < tempsTransition) {
double progression = timeStamp.TotalMilliseconds / tempsTransition.TotalMilliseconds; double progression = timeStamp.TotalMilliseconds / tempsTransition.TotalMilliseconds;
@ -341,6 +344,8 @@ namespace DMX2
if (index < effets.Count) if (index < effets.Count)
ChangeEffetCourrant (index); ChangeEffetCourrant (index);
} }
} finally {
Monitor.Exit (this);
} }
} }

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml; using System.Xml;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Threading;
namespace DMX2 namespace DMX2
{ {
@ -311,10 +312,9 @@ namespace DMX2
return; return;
timeStamp += time; timeStamp += time;
if (Monitor.TryEnter (this)) {
lock (this) { try {
if(effetsEnCours.Count>0) if (effetsEnCours.Count > 0) {
{
List<Circuit> circuits = new List<Circuit> (effetsEnCours.Keys); List<Circuit> circuits = new List<Circuit> (effetsEnCours.Keys);
foreach (Circuit c in circuits) { foreach (Circuit c in circuits) {
@ -326,13 +326,16 @@ namespace DMX2
} }
} }
} }
}
if (topPresent) { if (topPresent) {
if (timeStamp > topSuivant) { if (timeStamp > topSuivant) {
LigneSuivante (); LigneSuivante ();
} }
} }
} finally {
Monitor.Exit (this);
}
}
} }
public void LigneSuivante () public void LigneSuivante ()