Пример #1
0
        // for NET_1_0 and NET_1_1 no (public) ExecutionContext exists
        // so we must use the System.Threading.CompressedStack class
        internal static void ExecuteClientMessage(GCHandle gchandle)
        {
            AsyncMethodData data     = (AsyncMethodData)gchandle.Target;
            CompressedStack original = null;

#if !MWF_ON_MSRUNTIME
            // Stack is non-null only if the security manager is active
            if (data.Stack != null)
            {
                original = Thread.CurrentThread.GetCompressedStack();
                Thread.CurrentThread.SetCompressedStack(data.Stack);
            }
#endif

            AsyncMethodResult result = data.Result;
            object            ret;

            try {
                ret = data.Method.DynamicInvoke(data.Args);
                result.Complete(ret);
            } catch (Exception ex) {
                result.CompleteWithException(ex);
                return;
            } finally {
#if !MWF_ON_MSRUNTIME
                if (data.Stack != null)
                {
                    // whatever occurs we must revert to the original compressed
                    // stack (null being a valid, empty, value in this case).
                    Thread.CurrentThread.SetCompressedStack(original);
                }
#endif
                gchandle.Free();
            }
        }
Пример #2
0
        internal static void ExecutionCallback(object state)
        {
            AsyncMethodData   data   = (AsyncMethodData)state;
            AsyncMethodResult result = data.Result;

            object ret;

            try
            {
                ret = data.Method.DynamicInvoke(data.Args);
            }
            catch (Exception ex)
            {
                if (result != null)
                {
                    result.CompleteWithException(ex);
                    return;
                }

                throw;
            }

            if (result != null)
            {
                result.Complete(ret);
            }
        }