diff options
Diffstat (limited to 'cs/src/Ice/Timer.cs')
-rw-r--r-- | cs/src/Ice/Timer.cs | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/cs/src/Ice/Timer.cs b/cs/src/Ice/Timer.cs index 23bcc7bce12..23f1335640e 100644 --- a/cs/src/Ice/Timer.cs +++ b/cs/src/Ice/Timer.cs @@ -18,6 +18,7 @@ namespace IceInternal using System; using System.Diagnostics; using System.Threading; + using System.Collections; using System.Collections.Generic; public interface TimerTask @@ -66,7 +67,16 @@ namespace IceInternal try { _tasks.Add(task, token); +#if SILVERLIGHT + int index = _tokens.BinarySearch(token); + Debug.Assert(index < 0); + if(index < 0) + { + _tokens.Insert(~index, token); + } +#else _tokens.Add(token, null); +#endif } catch(System.ArgumentException) { @@ -99,7 +109,16 @@ namespace IceInternal try { _tasks.Add(task, token); +#if SILVERLIGHT + int index = _tokens.BinarySearch(token); + Debug.Assert(index < 0); + if(index < 0) + { + _tokens.Insert(~index, token); + } +#else _tokens.Add(token, null); +#endif } catch(System.ArgumentException) { @@ -145,17 +164,27 @@ namespace IceInternal // // Only for use by Instance. // +#if !SILVERLIGHT internal Timer(IceInternal.Instance instance, ThreadPriority priority) { init(instance, priority, true); } - +#endif + internal Timer(IceInternal.Instance instance) { +#if !SILVERLIGHT init(instance, ThreadPriority.Normal, false); +#else + init(instance); +#endif } - internal void init(IceInternal.Instance instance, ThreadPriority priority, bool hasPriority) +#if !SILVERLIGHT + internal void init(IceInternal.Instance instance, ThreadPriority priority, bool hasPriority) +#else + internal void init(IceInternal.Instance instance) +#endif { _instance = instance; @@ -168,10 +197,12 @@ namespace IceInternal _thread = new Thread(new ThreadStart(Run)); _thread.IsBackground = true; _thread.Name = threadName + "Ice.Timer"; +#if !SILVERLIGHT if(hasPriority) { _thread.Priority = priority; } +#endif _thread.Start(); } @@ -194,7 +225,16 @@ namespace IceInternal if(_tasks.ContainsKey(token.task)) { token.scheduledTime = Time.currentMonotonicTimeMillis() + token.delay; +#if SILVERLIGHT + int index = _tokens.BinarySearch(token); + Debug.Assert(index < 0); + if(index < 0) + { + _tokens.Insert(~index, token); + } +#else _tokens.Add(token, null); +#endif } } } @@ -221,7 +261,11 @@ namespace IceInternal long now = Time.currentMonotonicTimeMillis(); Token first = null; +#if SILVERLIGHT + foreach(Token t in _tokens) +#else foreach(Token t in _tokens.Keys) +#endif { first = t; break; @@ -351,6 +395,8 @@ namespace IceInternal #if COMPACT private IDictionary<Token, object> _tokens = new SortedList<Token, object>(); +#elif SILVERLIGHT + private List<Token> _tokens = new List<Token>(); #else private IDictionary<Token, object> _tokens = new SortedDictionary<Token, object>(); #endif @@ -361,5 +407,6 @@ namespace IceInternal private Thread _thread; private readonly IceUtilInternal.Monitor _m = new IceUtilInternal.Monitor(); - } +} + } |