Пример #1
0
 public void Repeat(Action stepFunc, int repetitions)
 {
     for (int i = 0; i < repetitions; i++)
     {
         DoWorkSync.WaitOne();
         stepFunc();
         WorkDoneSync.Set();
         if (ShouldStopScript)
         {
             ShouldStopScript = false;
             return;
         }
     }
 }
Пример #2
0
        public void Repeat(Action <object[]> stepFunc, int repetitions, params object[] parameters)
        {
            for (int i = 0; i < repetitions; i++)
            {
                DoWorkSync.WaitOne();
                stepFunc(parameters);
                WorkDoneSync.Set();

                if (ShouldStopScript)
                {
                    ShouldStopScript = false;
                    return;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// This method synchronize execution of given function and ToyWorld.
        /// The function is called once per ToyWorld execution step until the function
        /// returns true.
        /// </summary>
        /// <param name="stepFunc">A function changing or observing ToyWorld. Returns bool.</param>
        /// <param name="parameters">Any parameters the function accepts.</param>
        public void Do(Func <object[], bool> stepFunc, params object[] parameters)
        {
            for (int i = 0; i < MAXIMUM_NUMBER_OF_DO_METHED_CALLS; i++)
            {
                DoWorkSync.WaitOne();
                object o = stepFunc(parameters);
                WorkDoneSync.Set();

                if (ShouldStopScript)
                {
                    ShouldStopScript = false;
                    return;
                }
                bool end = (bool)o;
                if (end)
                {
                    return;
                }
            }
            throw new Exception("Too long time in Do function.");
        }
Пример #4
0
 public void Perform(Action <object[]> stepFunc, params object[] parameters)
 {
     DoWorkSync.WaitOne();
     stepFunc(parameters);
     WorkDoneSync.Set();
 }