locked
Asynch Commands in Acropolis? RRS feed

  • Question

  • Hi,

     

    Is there any example on how to implement Asynch Commands in Acropolis?

     

    Tuesday, August 28, 2007 7:17 AM

Answers

  • No, unfortunately there weren't any samples that exercised the async command capabilities.

     

    In terms of implementing the command itself however, there shouldn't be anything special you need to do.  Just implement the command like you normally would but make sure and follow the background threading rules (don't play with UI controls, take locks on shared resources, etc...).

     

    The real difference is in how the command is initiated, by calling BeginExecute() and EndExecute() instead of by calling Execute().  The caller is really the one that sees the differences between sync and async execution of commands.

     

    Tuesday, September 4, 2007 7:25 PM

All replies

  • No, unfortunately there weren't any samples that exercised the async command capabilities.

     

    In terms of implementing the command itself however, there shouldn't be anything special you need to do.  Just implement the command like you normally would but make sure and follow the background threading rules (don't play with UI controls, take locks on shared resources, etc...).

     

    The real difference is in how the command is initiated, by calling BeginExecute() and EndExecute() instead of by calling Execute().  The caller is really the one that sees the differences between sync and async execution of commands.

     

    Tuesday, September 4, 2007 7:25 PM
  • Hi,

     

    What I really ment is How to Make ComponentCommand connection popint to be asycnhronious, or if it is already asynch how to use it.

    As I saw there is ReportProgress, SupportCancelation on that connection point but can't see how to use this ?

     

    Anyone know?

     

    Thanks,

     

    Monday, September 24, 2007 1:56 PM
  • Hi Alex,

     

    There are two parts to doing Async commands.  The first is in the command itself.  When a command gets invoked, it's

    CommandExecuted event is fired and the event args that are passed in are of type

    ComponentCommandExecutionEventArgs.  On this event args object you will find a property called ExecutingOperation that represents the current invocation of the command.  This property is of type IOperation and it is the controller for the execution of the command.  During command processing you should periodically check to see if e.ExecutingOperation.CancellationRequested is set to true, if it is then you should 'cancel' the command in whatever way makes sense for that command.  Also, during command processing you should periodically call e.ExecutingOperation.ReportProgress() to report the progress of your command back to the command invoker.  From a command implementors standpoint that's about all you need to do to support Async commands (the command itself doesn't really know or care if it is being invoked synchronously or asynchronously).

     

    The second part is from the invokers perspective.  When executing a command you should use the BeginExecute() API to start the execution asynchronously.  This API will return an IOperation that represents the invocation of the command.  From your UI you can use this object to cancel the operation in response to say the user hitting a cancel button by calling the CancelExecution() method.  You can also monitor the progress of the operation by watching the ExecutionState property and waiting until it is set to a value of OperationExecutionState.Complete.  If you want to get progress report updates you can pass in a callback delegate to the BeginExecute() method and that delegate will get called back whenever the state or progress of the execution changes.  Calling EndExecute() at any point on the UI thread will retrieve the results of the command invocation (note calling this method will block the UI thread if the command has not yet completed executing, check the ExecuteState property on the IOperation object if you want to avoid blocking and only call EndExecute once the state is set to Complete).

     

    Thanks,

     

    Monday, September 24, 2007 4:32 PM