【问题标题】:Windows Forms application is not able to access DVD-Rom resourcesWindows 窗体应用程序无法访问 DVD-Rom 资源
【发布时间】:2015-06-06 12:44:21
【问题描述】:

我创建了一个桌面应用程序,它从应用程序的当前路径加载一些文件,该程序运行良好,但从 DVD-Rom 运行时不读取文件。

我使用的是 Windows 8.1,顺便说一下,我也尝试以管理员身份运行该程序,但我得到了相同的结果。

这是我的代码的一部分:

 public void LoadTable()
        {
            if (File.Exists("table.bin"))
            {
                string[] _items = File.ReadAllLines("table.bin");
                for (int i = 0; i < _items.Length; i++)
                {
                    string[] x = _items[i].Split(',');
                    if (x.Length > 5)
                    {
                        items.Add(new Item()
                        {
                            ID=x[0].Replace("*",""),
                        ThumbStart = x[1],
                        ThumbCount= x[2],
                        PackStart = x[3],
                        PackCount = x[4]
                        });
                        List<string> _cats = new List<string>();
                        for(int j = 5;j<x.Length;j++) _cats.Add(x[j]);
                        items[items.Count - 1].Categories = _cats.ToArray();
                    }
                }
            }
        }

是否与我的代码有关或有某些 Windows 设置?

【问题讨论】:

  • 您是否签署了已编译的应用程序?
  • @RowlandShaw nop 会是问题吗?
  • @RowlandShaw 我签了,但没有帮助
  • 你说“不读取文件”是什么意思?您是否遇到异常,或者似乎根本没有进入 for 循环?您是否尝试过像 Process Monitor (technet.microsoft.com/en-us/library/bb896645.aspx) 这样的工具来查看从 DVD 运行时“table.bin”I/O 的样子?工作目录可能不是您认为的那样。
  • @ScheuNZ 我以前没有使用过 Process Monitor。加载程序时,我正在读取 3 个文件(一个我已经包含在问题中,另外两个使用文件流,例如:FileStream("packs.bin", FileMode.Open),但由于源是只读的,我应该像这样使用:FileStream("packs.bin", FileMode.Open, FileAccess.Read)。非常感谢进程监视器作为没有它,我不会有任何线索。

标签: c# windows winforms


【解决方案1】:

如果您遇到文件 I/O 问题,可以使用 Sysinternals Suite 中的 Process Monitor (https://technet.microsoft.com/en-us/library/bb896645.aspx) 进行诊断。只需在重现问题时运行该工具并查找任何失败的 I/O 结果(可选择过滤以仅显示来自应用程序的 I/O)。

【讨论】:

    猜你喜欢
    • 2010-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多