diff options
Diffstat (limited to 'CSharp/Ivy')
-rw-r--r-- | CSharp/Ivy/IvyPPC/IvyClient.cs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/CSharp/Ivy/IvyPPC/IvyClient.cs b/CSharp/Ivy/IvyPPC/IvyClient.cs index 31ccdd5..360c9b1 100644 --- a/CSharp/Ivy/IvyPPC/IvyClient.cs +++ b/CSharp/Ivy/IvyPPC/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:
|