// flush out any pending invoker actions private void AwaitInvoker() { iInvoker.BeginInvoke(new Action(() => { iWaitHandleInvoker.Set(); })); Assert.That(iWaitHandleInvoker.WaitOne(kTimeoutMilliseconds)); }
public static AsyncCallback CreateInvokeCallback(this IInvoker invoker, AsyncCallback callback) { return(delegate(IAsyncResult result) { IAsyncResult rtmp = invoker.BeginInvoke(callback, null, result); invoker.EndInvoke(rtmp); }); }
//public static IAsyncResult BeginInvokeCallback(IInvoker proc_invoker, Delegate proc, IInvoker callback_invoker, AsyncCallback callback, params object[] proc_args) //{ // List<object> newargs = new List<object>(); // proc_invoker.BeginInvoke( // //IAsyncResult res=proc.DynamicInvoke( //} //public static IAsyncVoid InvokeVoid(SimpleCallback proc) //{ // AsyncAction res = new AsyncAction(proc); // ThreadPool.Invoke(res.DoRun); // return res.Async; //} //public static IAsyncValue<T> InvokeValue<T>(ReturnValueCallback<T> proc) //{ // AsyncResultAction<T> res = new AsyncResultAction<T>(proc); // ThreadPool.Invoke(res.DoRun); // return res.Async; //} //public static void InvokeVoid(SimpleCallback proc, IInvoker invoker, SimpleCallback onfinish) //{ // InvokeVoid(proc).OnFinish(onfinish, invoker); //} public static AsyncCallback CreateGenericInvokeCallback(this IInvoker invoker, Delegate callback, params object[] args) { return(delegate(IAsyncResult result) { List <object> newargs = new List <object>(); newargs.Add(result); newargs.AddRange(args); IAsyncResult rtmp = invoker.BeginInvoke(callback, null, newargs.ToArray()); invoker.EndInvoke(rtmp); }); }
public static void Invoke4 <T1, T2, T3, T4>(this IInvoker conn, Action <T1, T2, T3, T4> func, T1 p1, T2 p2, T3 p3, T4 p4) { if (conn.IsInInvokerThread) { func(p1, p2, p3, p4); return; } IAsyncResult res = conn.BeginInvoke((Action) delegate() { func(p1, p2, p3, p4); }, null, null); Async.WaitFor(res); conn.EndInvoke(res); }
public static void Invoke1 <T1>(this IInvoker conn, Action <T1> func, T1 p1) { if (conn.IsInInvokerThread) { func(p1); return; } IAsyncResult res = conn.BeginInvoke((Action) delegate() { func(p1); }, null, null); Async.WaitFor(res); conn.EndInvoke(res); }
public static void Invoke(this IInvoker conn, Action func) { if (conn.IsInInvokerThread) { func(); return; } IAsyncResult res = conn.BeginInvoke(func, null, null); Async.WaitFor(res); conn.EndInvoke(res); }
public static R InvokeR4 <R, T1, T2, T3, T4>(this IInvoker conn, Func <T1, T2, T3, T4, R> func, T1 p1, T2 p2, T3 p3, T4 p4) { if (conn.IsInInvokerThread) { return(func(p1, p2, p3, p4)); } IAsyncResult res = conn.BeginInvoke((Func <R>) delegate() { return(func(p1, p2, p3, p4)); }, null, null); Async.WaitFor(res); return((R)conn.EndInvoke(res)); }
public static R InvokeR1 <R, T1>(this IInvoker conn, Func <T1, R> func, T1 p1) { if (conn.IsInInvokerThread) { return(func(p1)); } IAsyncResult res = conn.BeginInvoke((Func <R>) delegate() { return(func(p1)); }, null, null); Async.WaitFor(res); return((R)conn.EndInvoke(res)); }
private void CheckForUpdates(object sender, EventArgs e) { lock (iLock) { Assert.Check(!iDisposed); if (iCancelTokenSource != null) { iCancelTokenSource.Cancel(); } iCancelTokenSource = new CancellationTokenSource(); var cancelToken = iCancelTokenSource.Token; var previousVersion = iCurrentVersion; iNotificationServer.Check(previousVersion, cancelToken).ContinueWith(t => { iInvoker.BeginInvoke(new Action(() => { if (!cancelToken.IsCancellationRequested) { if (t.IsFaulted) { t.Exception.Handle((ex => { return(true); })); UserLog.WriteLine("Error checking Upgrade Feed: " + t.Exception.GetBaseException()); } else { var current = GetNextNotification(previousVersion, t.Result); if (current != null) { Notification notification = null; notification = new Notification(current.Version, current.Uri, current.Version <= iNotificationPersistence.LastAcknowledgedNotificationVersion, () => { lock (iLock) { iNotificationPersistence.LastShownNotification = DateTime.Now; } }, (acknowledged) => { if (iNotificationPersistence.LastNotificationVersion < current.Version) { iNotificationPersistence.LastNotificationVersion = current.Version; } if (acknowledged) { if (iNotificationPersistence.LastAcknowledgedNotificationVersion < current.Version) { iNotificationPersistence.LastAcknowledgedNotificationVersion = current.Version; } // event out the changed acknowledgment status notification.HasBeenAcknowledged = true; iView.Update(notification, false); } }); iView.Update(notification, current.Version > previousVersion || (TimespanElapsed() && !notification.HasBeenAcknowledged)); lock (iLock) { iCurrentVersion = current.Version; } } } } })); }); } }
public static IAsyncResult BeginInvoke(this IInvoker conn, PriorityLevel priority, bool behaveAsStack, Delegate proc, AsyncCallback callback, params object[] args) { return(conn.BeginInvoke(priority, behaveAsStack, new SimpleAction(proc, args), callback)); }
public static IAsyncResult BeginInvoke(this IInvoker conn, Delegate proc, AsyncCallback callback, params object[] args) { return(conn.BeginInvoke(PriorityLevel.Normal, false, new SimpleAction(proc, args), callback)); }