public partial class MainWindow : Window, IPgrogressHandler
private void Button1_OnClick(object sender, RoutedEventArgs e)
var plugin = ResolvePluginFromDiContainer();
var something = plugin.RequestSomething();
Label2.Content = something;
System.Diagnostics.Trace.TraceError("{0}", ex);
private IPlugin ResolvePluginFromDiContainer()
return new SyncAdapterPlugin(this);
bool IPgrogressHandler.NotifyNewValueProgress(string s)
string RequestSomething();
public interface IPgrogressHandler
bool NotifyNewValueProgress(string s);
public class SyncAdapterPlugin : IPlugin, IProgressAsyncHandler
private readonly IPgrogressHandler _syncProgressHandler;
private TaskScheduler _context;
public SyncAdapterPlugin(IPgrogressHandler syncProgressHandler)
_syncProgressHandler = syncProgressHandler;
string IPlugin.RequestSomething()
_context = TaskScheduler.FromCurrentSynchronizationContext();
var asyncTarget = new ClassFromMyLibrary1(this);
var resultFromAsyncLibrary = asyncTarget.MethodFromAsyncLibrary("HelloFromPlugin").Result;
return resultFromAsyncLibrary;
async Task<bool> IProgressAsyncHandler.NotifyNewValueProgressAsync(string message)
Func<bool> work = () => _syncProgressHandler.NotifyNewValueProgress(message);
Task.Factory.StartNew(work, CancellationToken.None, TaskCreationOptions.None, _context)
public class ClassFromMyLibrary1
private readonly IProgressAsyncHandler _newValueHandler;
public ClassFromMyLibrary1(IProgressAsyncHandler newValueHandler)
_newValueHandler = newValueHandler;
public async Task<string> MethodFromAsyncLibrary(string key)
if (!await _newValueHandler.NotifyNewValueProgressAsync($"Getting remote value by key '{key}'").ConfigureAwait(false))
throw new OperationCanceledException("operation interrupted");
var remoteValue = await GetRemoteValueByKey(key).ConfigureAwait(false);
var newValue = $"Transformed-{remoteValue}";
if (!await _newValueHandler.NotifyNewValueProgressAsync($"New value received: '{newValue}'").ConfigureAwait(false))
throw new OperationCanceledException("operation interrupted");
private async Task<string> GetRemoteValueByKey(string key)
await Task.Delay(2000).ConfigureAwait(false);
return $"ValueFromRemoteLocationBy{key}";
public interface IProgressAsyncHandler
Task<bool> NotifyNewValueProgressAsync(string message);