public BEncodedDictionary EndCreate(IAsyncResult result) { Check.Result(result); if (result != _asyncResult) { throw new ArgumentException("The supplied async result does not correspond to currently active async result"); } try { if (!result.IsCompleted) { result.AsyncWaitHandle.WaitOne(); } if (_asyncResult.SavedException != null) { throw _asyncResult.SavedException; } return(_asyncResult.Aborted ? null : _asyncResult.Dictionary); } finally { _asyncResult = null; } }
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); }
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; }
public BEncodedDictionary EndCreate(IAsyncResult result) { Check.Result(result); if (result != _asyncResult) throw new ArgumentException("The supplied async result does not correspond to currently active async result"); try { if (!result.IsCompleted) result.AsyncWaitHandle.WaitOne(); if (_asyncResult.SavedException != null) throw _asyncResult.SavedException; return _asyncResult.Aborted ? null : _asyncResult.Dictionary; } finally { _asyncResult = null; } }