Exemplo n.º 1
0
        // Calls the given callback in the right context.
        // On any exception, calls onFail callback if any set.
        // If not set, exception is handled due to today we don't
        // have any scenario to propagate it from here.
        public unsafe static void CallInContext(IntPtr contextCallbackPtr, IntPtr contextToken, Action callback, Action onFailCallback)
        {
            // Check if we are already on the same context, if so we do not need to switch.
            if (contextCallbackPtr == IntPtr.Zero || GetContextToken() == contextToken)
            {
                callback();
                return;
            }

            ComCallData data            = default;
            var         contextCallback = new ABI.WinRT.Interop.IContextCallback(ObjectReference <ABI.WinRT.Interop.IContextCallback.Vftbl> .FromAbi(contextCallbackPtr));

            try
            {
                contextCallback.ContextCallback(_ =>
                {
                    callback();
                    return(0);
                }, &data, IID_ICallbackWithNoReentrancyToApplicationSTA, 5);
            }
            catch (Exception)
            {
                onFailCallback?.Invoke();
            }
        }
Exemplo n.º 2
0
        protected override unsafe void Release()
        {
            ComCallData data = default;
            IntPtr      contextCallbackPtr = _contextCallbackPtr;

            var contextCallback = new ABI.WinRT.Interop.IContextCallback(ObjectReference <ABI.WinRT.Interop.IContextCallback.Vftbl> .Attach(ref contextCallbackPtr));

            contextCallback.ContextCallback(_ =>
            {
                base.Release();
                return(0);
            }, &data, IID_ICallbackWithNoReentrancyToApplicationSTA, 5);
        }