Author: alanmc
Date: 2006-11-02 18:25:54 -0500 (Thu, 02 Nov 2006)
New Revision: 67304
Modified:
trunk/bitsharp/src/MonoTorrent.Client/ClientEngine.cs
trunk/bitsharp/src/MonoTorrent.Client/ConnectionListener.cs
Log:
Some fixes for the RemoveAll and Dispose methods
Modified: trunk/bitsharp/src/MonoTorrent.Client/ClientEngine.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/ClientEngine.cs 2006-11-02
23:17:27 UTC (rev 67303)
+++ trunk/bitsharp/src/MonoTorrent.Client/ClientEngine.cs 2006-11-02
23:25:54 UTC (rev 67304)
@@ -373,7 +373,10 @@
/// <param name="manager"></param>
public WaitHandle Remove(TorrentManager manager)
{
- WaitHandle handle = this.Stop(manager);
+ WaitHandle handle = null;
+ if (manager.State != TorrentState.Stopped)
+ handle = this.Stop(manager);
+
this.torrents.Remove(BitConverter.ToString(manager.Torrent.InfoHash));
manager.Dispose();
return handle;
@@ -385,11 +388,16 @@
/// </summary>
public WaitHandle[] RemoveAll()
{
- int i = 0;
WaitHandle[] handles = new WaitHandle[this.torrents.Count];
+ List<TorrentManager> mans = new
List<TorrentManager>(this.torrents.Count);
+
foreach (TorrentManager manager in this.torrents.Values)
- handles[i++] = this.Remove(manager);
+ mans.Add(manager);
+ this.torrents.Clear();
+ for (int i = 0; i < mans.Count; i++)
+ handles[i] = Remove(mans[i]);
+
return handles;
}
#endregion
@@ -585,11 +593,12 @@
public void Dispose(bool disposing)
{
WaitHandle[] handles = this.RemoveAll();
- if (handles.Length > 0)
- WaitHandle.WaitAll(handles);
+ for (int i = 0; i < handles.Length; i++)
+ if (handles[i] != null)
+ handles[i].WaitOne();
- foreach (KeyValuePair<string, TorrentManager> keypair in
this.torrents)
- keypair.Value.Dispose();
+ //foreach (KeyValuePair<string, TorrentManager> keypair in
this.torrents)
+ // keypair.Value.Dispose();
this.listener.Dispose();
this.timer.Dispose();
Modified: trunk/bitsharp/src/MonoTorrent.Client/ConnectionListener.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/ConnectionListener.cs 2006-11-02
23:17:27 UTC (rev 67303)
+++ trunk/bitsharp/src/MonoTorrent.Client/ConnectionListener.cs 2006-11-02
23:25:54 UTC (rev 67304)
@@ -161,7 +161,13 @@
/// <param name="disposing"></param>
public void Dispose(bool disposing)
{
- this.socket.Close();
+ try
+ {
+ this.socket.Close();
+ }
+ catch
+ {
+ }
}
#endregion
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches