/// <summary> /// Method for performing asynchronous method in a synchronous manner /// </summary> internal static T RunSync <T>(Func <Task <T> > taskFactory) { if (taskFactory == null) { throw new ArgumentNullException("taskFactory"); } using (var executeContext = new ExecuteSynchronizationContext()) { T result = default(T); executeContext.Post(async d => { using (executeContext.MessageLoopScoped()) { var task = taskFactory(); if (task == null) { throw new ArgumentException("taskFactory must get effective results"); } result = await task; } }, null); executeContext.BeginMessageLoop(); return(result); } }
public Disposable(ExecuteSynchronizationContext context) { this.context = context; }