示例#1
0
    public void AsyncEval(string code, JSReturnCallback callback, JSErrorCallback errorCallback)
    {
        var thread = new Thread(() => {
            try
            {
                var res = ctx.Eval(code);
                callback.Invoke(res);
            }
            catch (Exception ex)
            {
                errorCallback.Invoke(ex);
            }
        });

        thread.Start();
    }
示例#2
0
    public void AsyncTimedEval(Script code, int milliTimeout, JSCallback callback, JSErrorCallback errorCallback)
    {
        var thread = new Thread(() => {
            try
            {
                code.Evaluate(ctx);
                callback.Invoke();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    errorCallback.Invoke(ex);
                }
            }
        });
        var timeThread = new Thread(() =>
        {
            try
            {
                Thread.Sleep(Configurations.ScriptTimeout);
                if (thread.IsAlive)
                {
                    thread.Abort();
                    thread.Join();
                    errorCallback(new Exception("max time exceeded"));
                }
            }
            catch (Exception ex)
            {
                Debug.LogWarning("This is impossible!");
                Debug.LogError(ex);
            }
        });

        thread.Start();
        timeThread.Start();
    }