Quick question - how do I call async methods from within a Prism event aggregator subscriber action? E.g.
_eventAggregator.GetEvent<PubSubEvent<SomeMessage>>()
.Subscribe((msg) => {
DoSomething();
await DoSomethingAsync();
DoSomethingElse();
});
Just making @Charles Mager a answer
_eventAggregator.GetEvent<PubSubEvent<SomeMessage>>()
.Subscribe(async(msg) => {
DoSomething();
await DoSomethingAsync();
DoSomethingElse();
});
With current Prism implementation, it is not possible see here.
But I have found an alternate implementation of Prism's EventAggregator, which allows async
subscriptions. See here.
This new event async aggregator overloads can be used in the same way as the original one:
Subscription to event is exactly the same with another overload:
_eventAggregator.GetEvent<<TfsHookEvent<WorkItemUpdatedPayload>>().Subscribe(WorkItem_Updated);
Event handler:
private async Task WorkItem_Updated(WorkItemUpdatedPayload obj)
{
await CheckAsync();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With