本文整理汇总了C#中Tracker.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Tracker.Dispose方法的具体用法?C# Tracker.Dispose怎么用?C# Tracker.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tracker
的用法示例。
在下文中一共展示了Tracker.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleTracker
public SimpleTracker(string announcementEndpoint, string torrentsDirectoryPath)
{
// Make the listner.
var listener = new HttpListener(announcementEndpoint);
// Make the tracker.
Tracker = new Tracker ();
Tracker.AnnounceInterval = new TimeSpan (0, 1, 0);
Tracker.AllowUnregisteredTorrents = true;
Tracker.RegisterListener (listener);
// Make mappings.
Mappings = new ConcurrentDictionary<string, InfoHashTrackable> ();
// Make watcher.
Watcher = new TorrentFolderWatcher (torrentsDirectoryPath, "*.torrent");
Watcher.TorrentFound += (sender, e) =>
{
try
{
// Wait for file to finish copying.
System.Threading.Thread.Sleep (500);
// Make InfoHashTrackable from torrent.
var torrent = Torrent.Load (e.TorrentPath);
var trackable = new InfoHashTrackable (torrent);
// Add to tracker.
lock (Tracker)
Tracker.Add (trackable);
// Save to mappings.
Mappings[e.TorrentPath] = trackable;
// Log.
Console.WriteLine("Added {0}", e.TorrentPath);
}
catch (Exception exception)
{
Debug.WriteLine ("Error loading torrent from disk: {0}", exception.Message);
Debug.WriteLine ("Stacktrace: {0}", exception.ToString ());
}
};
Watcher.TorrentLost += (sender, e) =>
{
try
{
// Get from mappings.
var trackable = Mappings[e.TorrentPath];
// Remove from tracker.
lock(Tracker)
Tracker.Remove(trackable);
// Remove from mappings.
Mappings.TryRemove(e.TorrentPath, out trackable);
// Log.
Console.WriteLine("Removed {0}", e.TorrentPath);
}
catch(Exception exception)
{
Debug.WriteLine ("Error uploading torrent from disk: {0}", exception.Message);
Debug.WriteLine ("Stacktrace: {0}", exception.ToString ());
}
};
// Register close events.
AppDomain.CurrentDomain.ProcessExit += (sender, e) => Tracker.Dispose ();
// Run.
listener.Start();
Watcher.Start();
Watcher.ForceScan();
}
示例2: Should_not_fire_after_disposed
public void Should_not_fire_after_disposed()
{
var person = new Person();
var tracker = new Tracker().Track(person);
tracker.Dispose();
person.Name += "(changed)";
Assert.IsFalse(HasChange);
}