Beispiel #1
0
        protected CFRunLoopSourceCustom()
            : base(IntPtr.Zero, true)
        {
            gch = GCHandle.Alloc(this);
            var ctx = new CFRunLoopSourceContext();

            ctx.Info     = GCHandle.ToIntPtr(gch);
            ctx.Schedule = Marshal.GetFunctionPointerForDelegate(ScheduleDelegate);
            ctx.Cancel   = Marshal.GetFunctionPointerForDelegate(CancelDelegate);
            ctx.Perform  = Marshal.GetFunctionPointerForDelegate(PerformDelegate);

            var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CFRunLoopSourceContext)));

            try {
                Marshal.StructureToPtr(ctx, ptr, false);
                handle = CFRunLoopSourceCreate(IntPtr.Zero, 0, ptr);
            } finally {
                Marshal.FreeHGlobal(ptr);
            }

            if (handle == IntPtr.Zero)
            {
                throw new NotSupportedException();
            }
        }
Beispiel #2
0
        protected CFRunLoopSourceCustom()
            : base(IntPtr.Zero, true)
        {
            gch = GCHandle.Alloc(this);
            var ctx = new CFRunLoopSourceContext();

            ctx.Info     = GCHandle.ToIntPtr(gch);
            ctx.Schedule = Marshal.GetFunctionPointerForDelegate(ScheduleDelegate);
            ctx.Cancel   = Marshal.GetFunctionPointerForDelegate(CancelDelegate);
            ctx.Perform  = Marshal.GetFunctionPointerForDelegate(PerformDelegate);

            var handle = CFRunLoopSourceCreate(IntPtr.Zero, 0, ref ctx);

            InitializeHandle(handle);
        }
Beispiel #3
0
 extern static /* CFRunLoopSourceRef */ IntPtr CFRunLoopSourceCreate(/* CFAllocatorRef */ IntPtr allocator, /* CFIndex */ nint order, /* CFRunLoopSourceContext* */ ref CFRunLoopSourceContext context);