Esempio n. 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((ScheduleCallback)Schedule);
            ctx.Cancel   = Marshal.GetFunctionPointerForDelegate((CancelCallback)Cancel);
            ctx.Perform  = Marshal.GetFunctionPointerForDelegate((PerformCallback)Perform);

            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();
            }
        }
Esempio n. 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 ((ScheduleCallback)Schedule);
			ctx.Cancel = Marshal.GetFunctionPointerForDelegate ((CancelCallback)Cancel);
			ctx.Perform = Marshal.GetFunctionPointerForDelegate ((PerformCallback)Perform);

			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 ();
		}