Bug #357

avatar

TorrentManager.Stop() seems to be asynchronous

Added by Nik Ivanov 5169 days ago. Updated 4436 days ago.

Status:Rejected Start:03/01/2010
Priority:Normal Due date:
Assigned to:- % Done:

0%

Category:- Spent time: -
Target version:-
Votes: 0

Description

I'm trying to download a file from a multi-file torrent using MonoTorrent. I set the priority of the file to Immediate while all other files are Do Not Download. I monitor the file progress, and once it reaches 100%, I call:

torrentManager.Stop();
torrentEngine.Unregister(torrentManager);

The second line throws an exception:
Exception in mainloop
The manager must be stopped before it can be unregistered
at MonoTorrent.Client.MainLoop.QueueWait(DelegateTask t)
at MonoTorrent.Client.MainLoop.QueueWait(MainLoopTask task)
at MonoTorrent.Client.ClientEngine.Unregister(TorrentManager manager)

Is there a way to synchronously stop a torrent manager, so I can unregister it?

History

Updated by Nik Ivanov 5169 days ago

avatar

Forgot to mention:
This happens in MonoTorrent v0.80, release build.

Updated by Nik Ivanov 5167 days ago

avatar

The following workaround seems to work at simulating Stop function being synchronous:
This is part of the function where you want to stop and unload the manager:

torrentManager.TorrentStateChanged += new EventHandler<TorrentStateChangedEventArgs>(torrentManager_TorrentStateChanged);

torrentManager.Stop();
lock (ManagerUnloadedLock) {
Monitor.Wait(ManagerUnloadedLock);
}

This is the event handler:

private object ManagerUnloadedLock = new object();
void torrentManager_TorrentStateChanged(object sender, TorrentStateChangedEventArgs e) {
if (e.NewState == TorrentState.Stopped) {
try {
torrentEngine.Unregister(e.TorrentManager);
e.TorrentManager.Dispose();
}
catch (Exception ex) {
//handle exception here, shouldnt really happen
}
finally {
lock (ManagerUnloadedLock) {
Monitor.Pulse(ManagerUnloadedLock);
}
}
}
}

Updated by Alan McGovern 4953 days ago

avatar
  • Status changed from New to Rejected

It's asynchronous because several long-lasting tasks need to be performed when you stop a torrent. That's why the manager goes from Active -> Stopping and then from Stopping -> Stopped once those tasks have completed. These tasks can take up to 30 seconds to complete. I don't think making 'Stop' synchronous would be a good solution as the common usage of it would be to call it from a UI event and that would make the common usage block the calling application for a long period of time.

Updated by guyziiz guyziiz 4439 days ago

avatar

Thanks for the tips, maybe I can use this svelte my noesis marketing and I've been use whatsoever ethnical media in try a interaction and they eff handicraft a big friendliness on me.
<a href="http://www.insideyourrv.com/">Inside Your RV</a>

Updated by guyziiz guyziiz 4439 days ago

avatar

Its not the geostationary that commonwealth moldiness be completely fused with communicator's views neighboring musing. So this is what happened with me, anyways its a jazz toil, I revalue it. Thanks
Inside Your RV

Updated by janooishq janooishq 4436 days ago

avatar

Its not the geostationary that commonwealth moldiness be completely fused with communicator's views neighboring musing. So this is what happened with me, anyways its a blues toil, I revalue it. Thanks

BestJobDescriptions.com

Also available in: Atom PDF