From 5f7db294ca4772b0559b0759c8427eba1f6408e2 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:42:21 +0000 Subject: Utilisateur : Fcolin Date : 11/11/03 Heure : 20:54 Archivé dans $/EScribe/Ivy Commentaire: (vss 12) --- CSharp/Ivy/Ivy/Ivy.cs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'CSharp') diff --git a/CSharp/Ivy/Ivy/Ivy.cs b/CSharp/Ivy/Ivy/Ivy.cs index 56aa68c..b4a2ef4 100644 --- a/CSharp/Ivy/Ivy/Ivy.cs +++ b/CSharp/Ivy/Ivy/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"); -- cgit v1.1