This project is read-only.


CommandAsyncExecutor<TCommand> executes commands asynchronously using ThreadPool. In the opposite to the ThreadPool it notifies when the command is completed. CommandAsyncExecutor is a lightweight object and creating an instance of CommandAsyncExecutor for each command type is a common practice.

    public class CommandAsyncExecutor<TCommand> where TCommand : IMcmCommand
        public void ExecuteAsync(TCommand command) {...}
        public event CommandEventHandler<TCommand> ExecuteCompleted;
CommandEventHandler contains reference to the executed command.
CommandAsyncExecutor is created and used internally by Component.


private CommandAsyncExecutor<LoginCommand> _loginCommandAsyncExecutor;

private void handleLoginRequestMessage(LoginRequestMessage m)
    _loginCommandAsyncExecutor = new CommandAsyncExecutor<LoginCommand>();
    _loginCommandAsyncExecutor.ExecuteCompleted += on_loginCommandAsyncExecutor_ExecuteCompleted;

    var arg = new LoginCommandArgument(m.Name, Env.Components.TimeProvider);
    var cmd = new LoginCommand(arg);


private void on_loginCommandAsyncExecutor_ExecuteCompleted(object sender, CommandEventArgs<LoginCommand> e)
    var mes = new LoginResponseMessage(e.Command.Error);
    if (!mes.HasError)
        // no error
        mes.Greeting = e.Command.Result.Greeting;


Last edited Jan 24, 2013 at 10:05 PM by polo, version 4


No comments yet.