Beispiel #1
0
        public double wait()
        {
            var thread = (LuaThread)LuaThread.running().Values[0];
            var sw     = Stopwatch.StartNew();

            Action callback = null;

            callback = () =>
            {
                ScriptService.ResumeThread(thread);
                Disconnect(callback);
            };

            Connect(callback);
            ScriptService.YieldThread();
            return(sw.Elapsed.TotalSeconds);
        }
Beispiel #2
0
        public Instance WaitForChild(string name, double?timeout = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Name parameter cannot be empty.");
            }

            foreach (var c in Children)
            {
                if (c.Name == name)
                {
                    return(c);
                }
            }

            var thread = (LuaThread)LuaThread.running().Values[0];

            lock (Locker)
            {
                List <LuaThread> threads;
                if (_waitForChildList.TryGetValue(name, out threads))
                {
                    threads.Add(thread);
                }
                else
                {
                    _waitForChildList.Add(name, new List <LuaThread>(new[] { thread }));
                }
            }

            Timer timer       = null;
            var   timerAction = new TimerCallback(obj =>
            {
                ScriptService.ResumeThread(thread);
                timer?.Dispose();
            });

            timer = timeout == null ? new Timer(timerAction) : new Timer(timerAction, null, (int)(timeout * 1000), -1);

            ScriptService.YieldThread();

            return(FindFirstChild(name));
        }