堆栈溢出异常没有无限循环(据我可以告诉) [英] Stack overflow exception without infinite loop (as far as I can tell)

查看:292
本文介绍了堆栈溢出异常没有无限循环(据我可以告诉)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个堆栈溢出错误,而且我相当肯定我没有任何一种无限递归的(至少我在错误盯着几个小时了,我怎么也想不到它的循环。无限)

I have a stack overflow error, and I'm fairly sure I don't have any kind of infinite recursion (at least I've stared at the error for a few hours now and I can't imagine how its looping infinitely).

下面是代码:

    public decimal? Amount
    {
        get
        {
            if (!string.IsNullOrEmpty(_savedWork.Amount))
                return decimal.Parse(_savedWork.Amount);
            else
                return null;
        }
        set
        {
            if (value.HasValue)
            {
                _savedWork.Amount = value.Value.ToString();
                Percent = null;
            }
            else
                _savedWork.Amount = "";
            OnPropertyChanged("Amount");
        }
    }



#Note我住在一个字符串一个可空小数,这就是为什么我转换了。请不要让我进入我为什么这样做。

savedWork.Amount = value.Value。的ToString()是我的错误。

基本上,我在想,我的筹码仅仅是太小(或我的代码太大我想)。 我基本上运行此代码两次,它工作于一种形式的时候,而不是当我做的另一种形式,并把它放在那里,所以我觉得这两个形式之间的差异倾翻堆栈。

Basically I'm thinking that my stack is just too small (or my code is too big I suppose). I basically run this code twice, and it works when in one form, but not when I make another form and place it in there, so I think the difference between these 2 forms is tipping the stack.

有没有办法来确定什么,我做错了什么?我想找出代码的一部分占用了过多或持续时间过长等。

Is there a way to identify what I'm doing wrong? I want to find out what part of the code is taking up a too much or is persisting too long etc.

我做了有关如何栈/堆了一些研究工作,我知道PERFMON.EXE,但据我所知它仅适用于堆。是否有一个类似的工具,我可以用我的程序运行堆栈?

I've done some research about how the stack/heap work and I know about PerfMon.exe, but as far as I know it only works for the heap. Is there a similar tool that I can use for the stacks my program is running?

我发现的这个帖子约2工具名为的WinDbg 的和的 CDB 的,但我不能找到太多有关如何安装/使用它们。这些工具去?

I found this post about 2 tools called windbg and cdb but I can't find much about how to install/use them. Are these tools the right way to go?

另外,如果有一个无限循环或东西,将是巨大的。

Alternatively if there is an infinite loop or something that would be great.

下面是请求金额属性的代码(通过其自动生成的EntityFramework),因为我在评论中表示,踏入甚至没有到达这里。我真的认为只是触及我的堆栈限制。

here is the code requested for the Amount Property (its autogenerated by EntityFramework) as I said in the comments, the step into doesn't even reach here. I really do think my stack limit is just being reached.

  public global::System.String Amount
    {
        get
        {
            return _Amount;
        }
        set
        {
            OnAmountChanging(value);
            ReportPropertyChanging("Amount");
            _Amount = StructuralObject.SetValidValue(value, true);
            ReportPropertyChanged("Amount");
            OnAmountChanged();
        }
    }



最后修改



确定这样的元骑士的回答给我看,我的确有一个无限循环。我订阅了DisplayTypeOfInvestment(该金额属性属于类)的PropertyChanged事件的事件处理程序。该处理程序是这样的:

Final Edit

Ok so Meta-Knight's answer showed me that I did indeed have an infinite loop. I had an event handler subscribed to the PropertyChanged event of the DisplayTypeOfInvestment (the class that the Amount Property belongs to). The handler looked like this:

 void DisplayTypeOfInvestmentList_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
            _typeOfInvestmentFormSavedWork.TypeOfInvestment.Clear();
            foreach (DisplayInvestmentFund d in _displayInvestmentFundList)
            {
                _typeOfInvestmentFormSavedWork.TypeOfInvestment.Add(d.SavedWork);
            }

            OnPropertyChanged("TypeOfInvestmentFormSavedWork");

    }



TypeOfInvestmentFormSavedWork 是一个完全不同的类,它包含了它,它自己的版本SavedWork类的,我们看到使用了金额属性。此方法的要点是这个TypeOfInvestmentFormSavedWork属性更新_savedWork当金额属性更改的新值。出于某种原因,这是触发DisplayTypeOfInvestment视图模型的PropertyChanged的。我没有搞清楚,但我改变看起来像这样的方法:

The TypeOfInvestmentFormSavedWork is a completely different class that contains in it it's own version of the SavedWork class that we see that is used an the Amount property. The point of this method was to update this TypeOfInvestmentFormSavedWork property to the new value of _savedWork when the Amount property changes. For some reason this is triggering the DisplayTypeOfInvestment viewmodel's PropertyChanged. I didnt figure it out but I changed the method to look like this:

 void DisplayTypeOfInvestmentList_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "Amount" || e.PropertyName == "Percent")
        {
            _savedWork.TypeOfInvestment.Clear();
            foreach (DisplayInvestmentFund d in _displayInvestmentFundList)
            {
                _savedWork.TypeOfInvestment.Add(d.SavedWork);
            }

            OnPropertyChanged("CurrentWork");
        }
    }



if语句停止怪异特性的被改变DisplayInvestmentFund当Add方法被调用。

The if statement stops the weird properties being changed in the DisplayInvestmentFund when the Add method is called.

我知道这个答案犯规多大意义,但对我解释这全部细节将采取的非常长的时间。我也意识到,这可能意味着我的代码是坏的。我不知道该怎么办了。感谢您的帮助球员。

I realise this answer doesnt make much sense, but for me to explain this in full detail would take a very long time. I also realise that this probably means my code is bad. I'm not sure what to do about that. Thanks for the help guys.

推荐答案

有一定的金额二传手莫名其妙。您可以通过步入的属性,而不是跨过调试。如果设置VS所以它不会踏进属性,你仍然可以把你的断点制定者内部模拟跨进。至于VS不踏入的.edmx文件,CodeInChaos提到,也许类被标上的 DebuggerStepThrough 属性。

There must be a recursive call to the Amount setter somehow. You could debug it by "stepping into" the properties instead of stepping over. If you set VS so that it doesn't step into properties, you can still put a breakpoint inside your setters to simulate a "step into". As for VS not stepping into .edmx files, as CodeInChaos mentioned, maybe the class is tagged with a DebuggerStepThrough attribute.

这篇关于堆栈溢出异常没有无限循环(据我可以告诉)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆