示例#1
0
        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));
        }
示例#2
0
        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));
            }
        }
示例#3
0
        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));
        }