.NET Core应用程序因StackOverflowException而终止。

4
所以,我使用的是树莓派3b型号,并已成功运行了.NetCore v2.0.1。我已经能够构建CoreIOT Hello World项目,并在我的Pi上无问题地运行它,现在我有一些使用GPIO板创建的自定义硬件,我想到的唯一使用.NETCore的方法是使用文件系统方法/sys/class/gpio。我构建了一个非常小的应用程序:https://github.com/barkermn01/CanReader。里面没有什么东西,但出现了一个消息,说“由于StackOverflowException进程正在终止”,我不知道是什么原因导致的,我认为只是基本的文件系统读取,没有太大的东西。我唯一能想到的是它不喜欢无限循环。来自:https://github.com/barkermn01/CanReader/blob/master/Program.cs
while (!exiting)
{
    Console.Write("\rCurrent State " + state);
    string input = Console.ReadLine();
    if (input == "exit")
    {
        watcher.Stop();
        exiting = true;
    }
}

并从:https://github.com/barkermn01/CanReader/blob/master/GPIOWatcher.cs

(含义为:此文本提供了一个链接,指向GitHub上的代码文件GPIOWatcher.cs)
public void watch()
{
    GPIO.Value val = Gpio.ReadValue();
    while (val != OldValue)
    {
        val = Gpio.ReadValue();
        if (Delegate != null)
        {
            Delegate.DynamicInvoke();
        }
        Thread.Sleep(10);
    }
}
1个回答

11

检查GPIO.FullPath的属性获取器,它访问了自身:

   /// <summary>
    /// Generates the full path for the Filesystem mappings for this GPIO pin
    /// </summary>
    public string FullPath
    {
        get
        {
            return this.Path + "/" + this.FullPath;
        }
    }

我讨厌这种情况,明明是一件很简单的事情,但 Visual Studios 却没有发现。你本以为它会指出属性中的自引用。 - Barkermn01
我已经修改了它,但在回家之前无法测试,所以今晚会测试并告诉你。 - Barkermn01
谢谢,完美地解决了 :) 现在只需要弄清楚为什么它能够写入一个文件而不能写入其他文件 :) - Barkermn01

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接