public void Run(Action work) { work.BeginInvoke(asyncResult => { try { work.EndInvoke(asyncResult); } catch (Exception ex) { UIThread.Run(() => { throw ex; }); } }, null); }
public override void Dispose() { base.Dispose(); lock (asyncCounterSyncObj) { if (asyncCounter > 0) { int copyOfAsyncCounter = asyncCounter; UIThread.Run( () => { for (; copyOfAsyncCounter > 0; copyOfAsyncCounter--) { RaiseDataLoaded(copyOfAsyncCounter, string.Empty, string.Empty); } }); asyncCounter = 0; } } }
public void Run <T>(Func <T> work, Action <T> success = null, Action <Exception> error = null) { work.BeginInvoke(asyncResult => { try { var result = work.EndInvoke(asyncResult); if (success != null) { UIThread.Run(success, result); } } catch (Exception ex) { if (error != null) { UIThread.Run(error, ex); } } }, null); }