Like Rick asked in the comment, it depends on what you want to achieve...
If you use a Custom Resolver, you will always end up with Publish Transactions, even if you remove all the items from the resolved items list. Such Transactions will have a Warning state (that lets you know that something is fishy about them).
On the other hand if you use an Event System, you can stop the Transaction from being saved in the first place. But as far as I know, there is no other way to stop an action from within the event system apart from throwing an exception. Throwing one will result in stopping the action and the exception message showing up in Tridion's message center.
One last thing, for events handlers which need to do something with the "Subject" of the event, you should use (synchronous)
Subscribe, and not
SubscribeAsync. Async event handlers are exectued at one point, there is no guarantee when, and your handler code can end up executing "to late". In your example code you have async.
As far as I know, yes. You could try and check:
- The Publish Transaction's
State in your event handler,
In Progress being the first one
- plus whether the transaction matches your condition
and if both are true, then delete it. But, I haven't tested this.
That reason for checking the
State of transaction is because a
Save event is triggered many times for a single transaction. To be more precise, for every change that is happening inside it (State change, some other properties (ResovledItems, ProcessedItems, etc.) being set, etc.
Throwing an exception will show the message without any additional code needed.