public BEncodedDictionary EndCreate(IAsyncResult result) { Check.Result(result); if (result != this.asyncResult) { throw new ArgumentException("The supplied async result does not correspond to currently active async result"); } try { if (!result.IsCompleted) { result.AsyncWaitHandle.WaitOne(); } if (this.asyncResult.SavedException != null) { throw this.asyncResult.SavedException; } return(this.asyncResult.Aborted ? null : this.asyncResult.Dictionary); } finally { this.asyncResult = null; } }
public void AbortCreation() { TorrentCreatorAsyncResult r = asyncResult; if (r != null) { r.Aborted = true; } }
public TorrentCreatorAsyncResult BeginCreate(object asyncState, AsyncCallback callback) { if (result != null) { throw new TorrentException("You must call EndCreate before calling BeginCreate again"); } result = new TorrentCreatorAsyncResult(callback, asyncState); // Start the processing in a seperate thread, a user thread. new Thread(new ThreadStart(AsyncCreate)).Start(); return(result); }
IAsyncResult BeginCreate(MainLoopJob task, AsyncCallback callback, object asyncState) { if (asyncResult != null) { throw new InvalidOperationException("Two asynchronous operations cannot be executed simultaenously"); } asyncResult = new TorrentCreatorAsyncResult(callback, asyncState); ThreadPool.QueueUserWorkItem(delegate { try { asyncResult.Dictionary = (BEncodedDictionary)task(); } catch (Exception ex) { asyncResult.SavedException = ex; } asyncResult.Complete(); }); return(asyncResult); }
/// <summary> /// Ends the asynchronous torrent creation and returns the torrent in it's dictionary form /// </summary> /// <param name="result"></param> /// <returns></returns> public BEncodedDictionary EndCreate(IAsyncResult result) { Check.Result(result); if (result != this.result) throw new ArgumentException("The supplied async result does not correspond to currently active async result"); try { if (!result.IsCompleted) result.AsyncWaitHandle.WaitOne(); if (this.result.SavedException != null) throw this.result.SavedException; return this.result.Aborted ? null : this.result.Dictionary; } finally { this.result = null; } }
public TorrentCreatorAsyncResult BeginCreate(object asyncState, AsyncCallback callback) { if (result != null) throw new TorrentException("You must call EndCreate before calling BeginCreate again"); result = new TorrentCreatorAsyncResult(callback, asyncState); // Start the processing in a seperate thread, a user thread. new Thread(new ThreadStart(AsyncCreate)).Start(); return result; }
private IAsyncResult BeginCreate(MainLoopJob task, AsyncCallback callback, object asyncState) { if (asyncResult != null) throw new InvalidOperationException("Two asynchronous operations cannot be executed simultaenously"); asyncResult = new TorrentCreatorAsyncResult(callback, asyncState); ThreadPool.QueueUserWorkItem(delegate { try { asyncResult.Dictionary = (BEncodedDictionary) task(); } catch (Exception ex) { asyncResult.SavedException = ex; } asyncResult.Complete(); }); return asyncResult; }