Пример #1
0
        public static void Thread(IEnumerator routine, Func <int, string, Parameter[], bool> endonFunc)
        {
            bool threadActive = true;

            Func <bool> stepForward = new Func <bool>(() =>
            {
                if (!threadActive)
                {
                    return(false);
                }

                try
                {
                    if (!routine.Update())
                    {
                        threadActive = false;
                        return(false);
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    return(false);
                }
            });

            BaseScript.OnInterval(50, stepForward);

            void NotifyWaiter(int entRef, string notify, Parameter[] paras)
            {
                if (!threadActive)
                {
                    Notifiable.Notified -= NotifyWaiter;
                    return;
                }

                var returnType = endonFunc.Method.ReturnType;

                if (!(bool)endonFunc.DynamicInvoke(entRef, notify, paras))
                {
                    Notifiable.Notified -= NotifyWaiter;
                    threadActive         = false;
                    return;
                }
            }

            Notifiable.Notified += NotifyWaiter;
        }
Пример #2
0
        public static void Thread(IEnumerator routine)
        {
            Func <bool> stepForward = new Func <bool>(() =>
            {
                try
                {
                    if (!routine.Update())
                    {
                        return(false);
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    return(false);
                }
            });

            BaseScript.OnInterval(50, stepForward);
        }
Пример #3
0
 public ScriptThread(IEnumerator routine)
 {
     Routine = routine;
     BaseScript.OnInterval(50, () => StepForward());
 }