From ed5318f7fcb1540c1b9be9f3f66b02ac8ee2d2b1 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:46:25 +0000 Subject: Utilisateur : Fcolin Date : 14/11/03 Heure : 14:12 Archivé dans $/EScribe/Ivy Commentaire: (vss 15) --- CSharp/Ivy/Ivy/IvyClient.cs | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'CSharp/Ivy') diff --git a/CSharp/Ivy/Ivy/IvyClient.cs b/CSharp/Ivy/Ivy/IvyClient.cs index 31ccdd5..360c9b1 100644 --- a/CSharp/Ivy/Ivy/IvyClient.cs +++ b/CSharp/Ivy/Ivy/IvyClient.cs @@ -146,8 +146,8 @@ namespace IvyBus internal IvyClient(Ivy bus, MyTcpClient socket) { - regexp_in = new Hashtable(); - regexp_text = new Hashtable(); + regexp_in = Hashtable.Synchronized(new Hashtable()); + regexp_text = Hashtable.Synchronized(new Hashtable()); appName = "Unknown"; appPort = 0; this.bus = bus; @@ -246,14 +246,18 @@ namespace IvyBus internal int sendMsg(String message) { int count = 0; - foreach (Int32 key in regexp_in.Keys ) + lock( regexp_in.SyncRoot ) { - Regex regexp = (Regex) regexp_in[key]; - Match result = regexp.Match(message); - if (result.Success) + IDictionaryEnumerator myEnumerator = regexp_in.GetEnumerator(); + while ( myEnumerator.MoveNext() ) { - send(MessageType.Msg, key, result); - count++; + Regex regexp = (Regex) myEnumerator.Value; + Match result = regexp.Match(message); + if (result.Success) + { + send(MessageType.Msg, (int)myEnumerator.Key, result); + count++; + } } } return count; @@ -509,8 +513,14 @@ namespace IvyBus { try { - regexp_in.Add( msgId, new Regex(regexp,RegexOptions.Compiled|RegexOptions.IgnoreCase)); - regexp_text.Add( msgId, regexp); + lock( regexp_in.SyncRoot ) + { + regexp_in.Add( msgId, new Regex(regexp,RegexOptions.Compiled|RegexOptions.IgnoreCase)); + } + lock( regexp_text.SyncRoot ) + { + regexp_text.Add( msgId, regexp); + } } catch (ArgumentException e) { @@ -524,8 +534,14 @@ namespace IvyBus break; case MessageType.DelRegexp: - regexp_in.Remove(msgId); - regexp_text.Remove( msgId ); + lock( regexp_in.SyncRoot ) + { + regexp_in.Remove(msgId); + } + lock( regexp_text ) + { + regexp_text.Remove( msgId ); + } break; case MessageType.EndRegexp: -- cgit v1.1