示例#1
0
        /// <summary>
        /// Invokes a specific method
        /// </summary>
        /// <param name="m">Method</param>
        /// <param name="instance">object instance</param>
        /// <param name="p">Parameters</param>
        /// <returns></returns>
        public object Invoke(IMethod m, object instance, params object[] p)
        {
            object res = null;

            if (m is ILMethod)
            {
                ILIntepreter inteptreter = null;
                lock (freeIntepreters)
                {
                    if (freeIntepreters.Count > 0)
                    {
                        inteptreter = freeIntepreters.Dequeue();
                        //Clear debug state, because it may be in ShouldBreak State
                        inteptreter.ClearDebugState();
                    }
                    else
                    {
                        inteptreter = new ILIntepreter(this);
#if DEBUG
                        intepreters[inteptreter.GetHashCode()] = inteptreter;
                        debugService.ThreadStarted(inteptreter);
#endif
                    }
                }
                try
                {
                    res = inteptreter.Run((ILMethod)m, instance, p);
                }
                finally
                {
                    lock (freeIntepreters)
                    {
#if DEBUG
                        if (inteptreter.CurrentStepType != StepTypes.None)
                        {
                            //We should resume all other threads if we are currently doing stepping operation
                            foreach (var i in intepreters)
                            {
                                if (i.Value != inteptreter)
                                {
                                    i.Value.ClearDebugState();
                                    i.Value.Resume();
                                }
                            }
                            inteptreter.ClearDebugState();
                        }
#endif
                        inteptreter.Stack.ManagedStack.Clear();
                        inteptreter.Stack.Frames.Clear();
                        freeIntepreters.Enqueue(inteptreter);
#if DEBUG
                        //debugService.ThreadEnded(inteptreter);
#endif
                    }
                }
            }

            return(res);
        }