2

What is the difference between EventSystem.SubscribeAsync and EventSystem.Subscribe events in Tridion Event system? When we subscribed the events in EventSystem.SubscribeAsync and EventSystem.Subscribe with Transaction.committed phase, both events triggered at the same time (after Transaction.committed). We are trying to understand the difference between these two async and sync subscribe events.

this.EventSystem.SubscribeAsync(OnComponentCreate, EventPhases.TransactionCommitted);

this.EventSystem.Subscribe(OnComponentCreate, EventPhases.TransactionCommitted);

7

The difference is that on an ASYNC (SubscribeAsync) event, your code will run without blocking the main event from happening, while on SYNC events (Subscribe) the main event will wait for your code to run.

If you're doing content validation in your event, and you need to block a save from happening by throwing an error that should be displayed to the editor, then you need a Synchronous event.

If you're doing a logging action, that doesn't care about the editor's flow, then an asynchronous event would probably be better.

  • In Transaction Committed phase, when we subscribe Sync or Async what difference it would make. Does it make any difference ?Because anyways events are triggering after post transaction of certain action. – Nithya Oct 1 at 13:50
  • 1
    Functionally no difference. Technically, the same as for other events, the Tridion engine will wait for your code to complete before moving further (in case of sync). – Nuno Linhares Oct 1 at 14:04
  • Async events are more resource heavy (as they set up their own session). If the DB and Tridion servers have the extra resources to deal with that, fine - Async will give a better user experience. But if either is running close to peak load, then stick to sync as far as possible. For something as (hopefully light) as logging, I would use sync events always. Could of course have changed since I worked on it.... – Lars Møllebjerg Oct 2 at 8:33
  • Thanks @NunoLinhares and @ Lars Møllebjerg for your explanations. In terms of timings i wanted to understand if there is any time difference when sync or async are used in Transaction committed. – Nithya Oct 2 at 10:40
  • 1
    Handlers for TransactionCommitted are executed async in most cases, even if you subscribed through Subscribe() method. In fact, they are chained to the Transaction.Current.TransactionCompleted .NET event. So in your case (on component create), event will be executed async anyways. – AntonM Oct 3 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.