Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#

A Flexible Plugin System

Rate me:
Please Sign up or sign in to vote.
4.98/5 (25 votes)
3 Sep 2008LGPL34 min read 130.6K   1.8K   163  
A generic plugin system used to load and manage plugins
using System;
using System.Threading;

namespace Fadd.Commands
{
    /// <summary>
    /// Used to keep track of all asynchronous commands.
    /// </summary>
    internal class AsyncQueueItemResult : IAsyncResult
    {
        private bool _isCompleted;
        private readonly ManualResetEvent _asyncWaitHandle;
        private readonly object _asyncState;
        private readonly Command _command;
        private CommandEventArgs _args;

        public AsyncQueueItemResult(Command command, CommandEventArgs args,  object state)
        {
            _asyncWaitHandle = new ManualResetEvent(false);
            _asyncState = state;
            _command = command;
            _args = args;
        }

        internal void ToggleCompleted()
        {
            _isCompleted = true;
            _asyncWaitHandle.Set();
        }

        #region IAsyncResult Members

        ///<summary>
        ///Gets an indication whether the asynchronous operation has completed.
        ///</summary>
        ///
        ///<returns>
        ///true if the operation is complete; otherwise, false.
        ///</returns>
        ///<filterpriority>2</filterpriority>
        public bool IsCompleted
        {
            get { return _isCompleted; }
        }

        ///<summary>
        ///Gets a <see cref="T:System.Threading.WaitHandle"></see> that is used to wait for an asynchronous operation to complete.
        ///</summary>
        ///
        ///<returns>
        ///A <see cref="T:System.Threading.WaitHandle"></see> that is used to wait for an asynchronous operation to complete.
        ///</returns>
        ///<filterpriority>2</filterpriority>
        public WaitHandle AsyncWaitHandle
        {
            get { return _asyncWaitHandle; }
        }

        ///<summary>
        ///Gets a user-defined object that qualifies or contains information about an asynchronous operation.
        ///</summary>
        ///
        ///<returns>
        ///A user-defined object that qualifies or contains information about an asynchronous operation.
        ///</returns>
        ///<filterpriority>2</filterpriority>
        public object AsyncState
        {
            get { return _asyncState; }
        }

        ///<summary>
        ///Gets an indication of whether the asynchronous operation completed synchronously.
        ///</summary>
        ///
        ///<returns>
        ///true if the asynchronous operation completed synchronously; otherwise, false.
        ///</returns>
        ///<filterpriority>2</filterpriority>
        public bool CompletedSynchronously
        {
            get { return false; }
        }

        public Command Command
        {
            get { return _command; }
        }

        public CommandEventArgs Args
        {
            get { return _args; }
        }

        #endregion
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder 1TCompany AB
Sweden Sweden

Comments and Discussions