Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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;
            }
        }