diff options
-rw-r--r-- | CSharp/Ivy/IvyPPC/Ivy.cs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/CSharp/Ivy/IvyPPC/Ivy.cs b/CSharp/Ivy/IvyPPC/Ivy.cs index 56aa68c..b4a2ef4 100644 --- a/CSharp/Ivy/IvyPPC/Ivy.cs +++ b/CSharp/Ivy/IvyPPC/Ivy.cs @@ -195,6 +195,7 @@ namespace IvyBus watchers.Add(watcher);
}
serverThread = new Thread(new ThreadStart(this.Run));
+ serverThread.Name = "Ivy Tcp Server Thread";
serverThread.Start();
// sends the broadcasts and listen to incoming connexions
for (int i = 0; i < watchers.Count; i++)
@@ -239,10 +240,12 @@ namespace IvyBus try
{
// stopping the serverThread
- Thread t = serverThread;
- serverThread = null;
- if (t != null)
- t.Interrupt();
+ if (serverThread != null)
+ {
+ app.Stop();
+ serverThread.Join();
+ serverThread = null;
+ }
// The serverThread might be stopped even before having been created
if (app != null)
app.Stop();
@@ -254,18 +257,20 @@ namespace IvyBus }
// stopping the remaining IvyClients
// copy the values in temporary variable to eliminate Thread modifying collection
- IvyClient[] copyClient;
- copyClient = new IvyClient[clients.Count];
- lock( clients.SyncRoot )
+ if ( clients.Count != 0 )
{
- clients.Values.CopyTo( copyClient,0 );
- }
- foreach (IvyClient client in copyClient )
+ IvyClient[] copyClient;
+ copyClient = new IvyClient[clients.Count];
+ lock( clients.SyncRoot )
+ {
+ clients.Values.CopyTo( copyClient,0 );
+ }
+ foreach (IvyClient client in copyClient )
{
client.close(true); // will notify the reading thread
//removeClient(client); already donne in the thread
}
-
+ }
}
catch (IOException e)
{
@@ -603,12 +608,6 @@ namespace IvyBus Console.Out.WriteLine("Ivy server socket reader caught an exception " + e.Message);
// e.printStackTrace();
}
- catch (ThreadInterruptedException te)
- {
- Console.Error.WriteLine( te.Message );
- Console.Error.WriteLine( te.StackTrace);
- running = false;
- }
catch (SocketException e)
{
traceDebug("my server socket has been closed");
|