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));
        }
Beispiel #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));
            }
        }
Beispiel #3
0
 public static DispatchBlock Create(DispatchBlock block, DispatchBlockFlags flags, DispatchQualityOfService qosClass, int relative_priority)
 {
     if (block == null)
     {
         throw new ArgumentNullException(nameof(block));
     }
     return(block.Create(flags, qosClass, relative_priority));
 }
Beispiel #4
0
        public void DispatchAfter(DispatchTime when, DispatchBlock block)
        {
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            dispatch_after(when.Nanoseconds, GetCheckedHandle(), block.GetCheckedHandle());
        }
Beispiel #5
0
        public void DispatchBarrierSync(DispatchBlock block)
        {
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            dispatch_barrier_sync(GetCheckedHandle(), block.GetCheckedHandle());
        }
Beispiel #6
0
 public void Notify(DispatchQueue queue, Action notification)
 {
     if (notification == null)
     {
         throw new ArgumentNullException(nameof(notification));
     }
     using (var block = new DispatchBlock(notification))
         Notify(queue, block);
 }
Beispiel #7
0
 public void Notify(DispatchQueue queue, DispatchBlock block)
 {
     if (queue == null)
     {
         throw new ArgumentNullException(nameof(queue));
     }
     if (block == null)
     {
         throw new ArgumentNullException(nameof(block));
     }
     dispatch_group_notify(GetCheckedHandle(), queue.Handle, block.GetCheckedHandle());
 }
Beispiel #8
0
 public void Notify(DispatchQueue queue, DispatchBlock notification)
 {
     if (queue == null)
     {
         throw new ArgumentNullException(nameof(queue));
     }
     if (notification == null)
     {
         throw new ArgumentNullException(nameof(notification));
     }
     dispatch_block_notify(GetCheckedHandle(), queue.GetCheckedHandle(), notification.GetCheckedHandle());
 }
        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));
        }
Beispiel #10
0
 public DispatchBlock(DispatchBlock dispatchBlock, DispatchBlockFlags flags, DispatchQualityOfService qosClass, int relative_priority)
     : base(dispatch_block_create_with_qos_class((nuint)(ulong) flags, qosClass, relative_priority, Runtime.ThrowOnNull(dispatchBlock, nameof(dispatchBlock)).GetCheckedHandle()), true)
 {
 }