Example #1
0
 public WgLoopException(LeapInfo.LeapType Type, string LoopHeader)
 {
     LeapInfo = new LeapInfo
     {
         Type       = Type,
         LoopHeader = LoopHeader ?? WgContext.DefaultLoopLabel
     };
 }
Example #2
0
        // execution loop
        public void Run(WaitHandle ehStop)
        {
            while (!ehStop.WaitOne(0) && CallStack.Count > 0)
            {
                CallStackEntry CurrentEntry = CallStack.Pop();

                bool MustSkipForLeap = Leap != null &&
                                       !(CurrentEntry.LoopHeader != null && Leap.LoopHeader == DefaultLoopLabel) &&
                                       !(CurrentEntry.LoopHeader != null && Leap.LoopHeader == CurrentEntry.LoopHeader)
                ;

                if (CurrentEntry.Proc == null || MustSkipForLeap)
                {
                    continue;
                }

                // to keep data in stack
                if (CallStack.Count == 0 ||
                    !object.ReferenceEquals(CurrentEntry.Data, CallStack.Peek().Data)
                    )
                {
                    CallStack.Push(CallStackEntry.MakeEmpty(CurrentEntry.Data));
                }

                try
                {
                    CurrentEntry.Proc.Method.Invoke(null, BindingFlags.Default, null, new[] { this, (object)CurrentEntry.Data },
                                                    Thread.CurrentThread.CurrentCulture);

                    Leap = null;
                }
                catch (TargetInvocationException ex)
                {
                    if (ex.InnerException is WgLoopException)
                    {
                        Leap = ((WgLoopException)ex.InnerException).LeapInfo;
                    }
                    else
                    {
                        // here: handle, store and forward
                        throw;
                    }
                }

                // DEBUG
                if ((DateTime.Now.Second % 10) > 6)
                {
                    break;
                }
            }
        }