为什么调试器不能一致地命中断点?我是否忽略了文件句柄?

发布于 2024-08-07 22:35:41 字数 556 浏览 1 评论 0原文

考虑以下代码:

static void Main(string[] args)
{
    using (MemoryStream memoryStream = new MemoryStream(Resources.SampleXMLFile)) // Breakpoint set here
    {
        using (XmlTextReader xmlTextReader = new XmlTextReader(memoryStream))
        {
            var z = XElement.Load(xmlTextReader);
        }
    }
    Console.ReadLine();
}

我在第一个 using 语句上设置了断点。然而,调试器并没有一致地命中它。

我的问题:

为什么会发生这种情况?我是否忽略了文件句柄?

还:

这是打开嵌入资源 XML 文件的最佳方式吗?

Consider the following code:

static void Main(string[] args)
{
    using (MemoryStream memoryStream = new MemoryStream(Resources.SampleXMLFile)) // Breakpoint set here
    {
        using (XmlTextReader xmlTextReader = new XmlTextReader(memoryStream))
        {
            var z = XElement.Load(xmlTextReader);
        }
    }
    Console.ReadLine();
}

I have a breakpoint set on the first using statement. Yet, the debugger does not hit it consistently.

My question:

Why does this happen? Am I neglecting a file handle?

Also:

Is this the best way to open an embedded resource XML file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独自唱情﹋歌 2024-08-14 22:35:41

感谢所有看过这个问题的人。

以下是我解决此问题的方法:

关闭并重新打开 Visual Studio。

顺便说一句,我当时总共打开了三个 Visual Studio 实例。

我很遗憾没有考虑到我的机器可能没有足够的资源来执行代码。

Thanks to all who viewed this question.

Here is how I fixed this problem:

Closed and reopened Visual Studio.

As an aside, I had a total of three Visual Studio instances open at the time.

Shame on me for failing to consider that my machine might have had insufficient resources to execute the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文