English 中文(简体)
在PowerShell, 我如何配置调用深度?
原标题:How can I configure call depth in PowerShell?

我只是在PowerShell中尝试一些事情, 在一些测试循环函数中, 发现调用深度 设置为1000 出错。 我在互联网上查看了一些信息, 发现这是因为 PowerShell 处理错误( 如果正确的话 ) :

The recursion depth limit is fixed in version 1. Deep recursion was causing problems in 64-bit mode because of the way exceptions were being processed. It was causing cascading out-of-memory errors. The net result was that we hard-limited the recursion depth on all platforms to help ensure that scripts would be portable to all platforms. - Bruce Payette, co-designer of PowerShell

我发现它"http://weblogs.asp.net/jgallouway/archive/2011/12/15/work-around-a-powershell- call-product-disalution-with-trampolines.aspx" rel="不跟随">这里

我还在MSDN上找到了这个例外页面,其中指出这一限制是可配置的(但我没有发现任何关于如何配置的限制)——见评论部分这里

如何设定此限制? < / 强 >

最佳回答
  • In PowerShell V1 the maximum call depth is 100:

使用 < a href=" "http://en.wikipedia.org/wiki/.NET_Refector" rel="nofollow" >.NET Researchor ,我们从 System.management.ExectiveContext 类代码中可以看到此片段,

internal int IncrementScopeDepth()
{
    using (IDisposable disposable = tracer.TraceMethod("{0}", new object[] { this.scopeDepth }))
    {
        if (this.CurrentPipelineStopping)
        {
            throw new PipelineStoppedException();
        }
        this.scopeDepth++;
        if (this.scopeDepth > 100)
        {
            ScriptCallDepthException exceptionRecord = new
            ScriptCallDepthException(this.scopeDepth, 100);
            tracer.TraceException(exceptionRecord);
            throw exceptionRecord;
        }
        return this.scopeDepth;
    }
}

无法修改“加固”码为100

  • In PowerShell V2 the maximum call depth is 1000

当再次查看代码时,似乎没有办法绕过默认最大调用深度。

  • In PowerShell V3 (CTP) there doesn t seem to be a maximum call depth (unless you run out of resources of course). This behaviour has been described as a bug on connect, so it might change in the final version.
问题回答

暂无回答




相关问题
handling exceptions IN Action Filters

Is there a better way to handle exceptions that occur inside an Action Filter itself in ASP .NET MVC? There re 2 ways I can think of at the moment. Using a try catch and setting the HTTP Status ...

既可捕获,又可举出例外。

我有一种办法,可以进入亚洲开发银行,因此,我国的亚行在多瑙河航道中的所有 st子都位于一个试捕区。 它正在追捕Kexception

Cross compiler exception handling - Can it be done safely?

I am doing some maintenance on a C++ windows dll library that is required to work with different VC++ compilers (as I don’t want to address different mangling schemes). I have already eliminated any ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

Watch a memory location/install data breakpoint from code?

We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem happens only in release mode. ...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签