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 SetEventHandler(Action handler)
        {
            Check();
            if (handler == null)
            {
                dispatch_source_set_event_handler_f(handle, IntPtr.Zero);
                return;
            }

            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_event_handler(handle, block));
            }
        }