Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        public void AbortCreation()
        {
            TorrentCreatorAsyncResult r = asyncResult;

            if (r != null)
            {
                r.Aborted = true;
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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;
        }