Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Flexible Plugin System

, 3 Sep 2008
A generic plugin system used to load and manage plugins
fadd-15373.zip
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 Gauffin Interactive AB
Sweden Sweden
Founder of OneTrueError, a .NET service which captures, analyzes and provide possible solutions for exceptions.
 
blog | twitter
Follow on   Twitter   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 3 Sep 2008
Article Copyright 2008 by jgauffin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid