1

我有相对较长的初始代码,然后我使用引擎执行可能影响引擎状态的单个语句。我想通过不一直重新执行初始代码来加快速度。

是否有可能:

  • 快速克隆具有整个状态的引擎实例或
  • 快速保存和恢复引擎状态?

    private void RunScript()
    {
        var engine = new Engine();
    
        //Please note I am executing this only once:
        engine.Execute(@"
            var globalCounter = 0;
            var increaseCounter = function() { globalCounter++; return globalCounter; };
            ");
    
        //What I need:
        //engine.MagicallySaveState();
    
        var result1 = engine.Execute("increaseCounter()").GetCompletionValue().AsNumber();
        //result1==1
    
        //What I need:
        //engine.MagicallyRestoreState();
    
        var result2 = engine.Execute("increaseCounter()").GetCompletionValue().AsNumber();
        //result2 should be still 1 and not 2 if Save/Restore works;
    
    }
    
4

0 回答 0