namespace Caliburn.Micro.Core {
using System.Threading;
using System.Threading.Tasks;
///
/// Extensions for .
///
public static class EventAggregatorExtensions {
///
/// Publishes a message on the current thread (synchrone).
///
/// The event aggregator.
/// The message instance.
public static void PublishOnCurrentThread(this IEventAggregator eventAggregator, object message) {
eventAggregator.Publish(message, action => action());
}
///
/// Publishes a message on a background thread (async).
///
/// The event aggregator.
/// The message instance.
public static void PublishOnBackgroundThread(this IEventAggregator eventAggregator, object message) {
eventAggregator.Publish(message, action => Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default));
}
///
/// Publishes a message on the UI thread.
///
/// The event aggregator.
/// The message instance.
public static void PublishOnUIThread(this IEventAggregator eventAggregator, object message) {
eventAggregator.Publish(message, Execute.OnUIThread);
}
///
/// Publishes a message on the UI thread asynchrone.
///
/// The event aggregator.
/// The message instance.
public static void BeginPublishOnUIThread(this IEventAggregator eventAggregator, object message) {
eventAggregator.Publish(message, Execute.BeginOnUIThread);
}
///
/// Publishes a message on the UI thread asynchrone.
///
/// The event aggregator.
/// The message instance.
public static Task PublishOnUIThreadAsync(this IEventAggregator eventAggregator, object message) {
Task task = null;
eventAggregator.Publish(message, action => task = action.OnUIThreadAsync());
return task;
}
}
}