Click here to Skip to main content
13,192,426 members (47,384 online)
Click here to Skip to main content

Stats

91.7K views
1.6K downloads
162 bookmarked
Posted 29 Aug 2008

A Flexible Plugin System

, 3 Sep 2008
A generic plugin system used to load and manage plugins
trunk
dlls
xunit.dll
Examples
Plugins
ExampleApplication.Shared
Properties
ExampleApplication
Properties
ExamplePlugin.Shared
Properties
ExamplePlugin
Properties
Fadd.Globalization.Yaml
fadd.snk
Properties
Tests
fadd
Commands
Net
Tests
fadd.snk
Globalization
Tests
Logging
Plugins
Properties
Tests
Validation
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)

Share

About the Author

jgauffin
Founder 1TCompany AB
Sweden Sweden
Skip logfiles, try automated error handling!

I'm one of the founders of codeRR, a .NET service which takes care of everything related to exceptions, so that you can focus on writing code.

blog | twitter

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171017.2 | Last Updated 3 Sep 2008
Article Copyright 2008 by jgauffin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid