public void SetEventHandler(Action handler) { if (handler == null) { dispatch_source_set_event_handler_f(GetCheckedHandle(), IntPtr.Zero); return; } DispatchBlock.Invoke( delegate { var sc = SynchronizationContext.Current; if (sc == null) { SynchronizationContext.SetSynchronizationContext(new DispatchQueueSynchronizationContext(queue)); } try { handler(); } finally { if (sc == null) { SynchronizationContext.SetSynchronizationContext(null); } } }, block => dispatch_source_set_event_handler(GetCheckedHandle(), block)); }
public void SetCancelHandler(Action handler) { if (handler == null) { throw new ArgumentNullException("handler"); } Check(); unsafe { DispatchBlock.Invoke( delegate { var sc = SynchronizationContext.Current; if (sc == null) { SynchronizationContext.SetSynchronizationContext(new DispatchQueueSynchronizationContext(queue)); } try { handler(); } finally { if (sc == null) { SynchronizationContext.SetSynchronizationContext(null); } } }, block => dispatch_source_set_cancel_handler(handle, block)); } }
public void SetRegistrationHandler(Action handler) { if (handler == null) { throw new ArgumentNullException("handler"); } DispatchBlock.Invoke( delegate { var sc = SynchronizationContext.Current; if (sc == null) { SynchronizationContext.SetSynchronizationContext(new DispatchQueueSynchronizationContext(queue)); } try { handler(); } finally { if (sc == null) { SynchronizationContext.SetSynchronizationContext(null); } } }, block => dispatch_source_set_registration_handler(GetCheckedHandle(), block)); }