public override void Post(SendOrPostCallback d, object state)
        {
            if (d == null)
            {
                throw new ArgumentNullException(nameof(d));
            }

            var data   = new InvokeState(d, state, false);
            var handle = GCHandle.Alloc(data, GCHandleType.Normal);

            GLib.ContextInvoke(IntPtr.Zero, InvokeCallback, GCHandle.ToIntPtr(handle));
        }
Esempio n. 2
0
        static partial void InvokeImpl(Action action)
        {
            using (var mre = new ManualResetEventSlim(false))
            {
                // if on main thread, callback is executed immediately
                // and mre is set before calling Wait().
                // Otherwise we block the calling thread until the action is executed.
                GLib.ContextInvoke(
                    IntPtr.Zero,
                    data =>
                {
                    try { action(); }
                    finally { mre.Set(); }

                    return(false);
                },
                    IntPtr.Zero);

                mre.Wait();
            }
        }
        public override void Send(SendOrPostCallback d, object state)
        {
            if (d == null)
            {
                throw new ArgumentNullException(nameof(d));
            }

            if (IsMainThread)
            {
                d(state);
            }
            else
            {
                var data   = new InvokeState(d, state, true);
                var handle = GCHandle.Alloc(data, GCHandleType.Normal);

                lock (data)
                {
                    GLib.ContextInvoke(IntPtr.Zero, InvokeCallback, GCHandle.ToIntPtr(handle));
                    Monitor.Wait(data);
                }
            }
        }