C# 3.0 C#两次访问相同资源的例外情况

C# 3.0 C#两次访问相同资源的例外情况,c#-3.0,C# 3.0,使用Windows窗体并在按钮单击处理程序中调用WordNet API: frmWordnetAPI relatedWords = new frmWordnetAPI (); relatedWords.ShowDialog(); 此API正在从源文件目录获取一些数据 编译程序时,在第一个按钮上单击,表单正在完美加载,但当我关闭API并再次单击按钮加载时,它会抛出一个异常,说明: The process cannot access the file 'D:\MIT\project

使用Windows窗体并在按钮单击处理程序中调用WordNet API:

frmWordnetAPI relatedWords = new frmWordnetAPI ();
        relatedWords.ShowDialog();
此API正在从源文件目录获取一些数据

编译程序时,在第一个按钮上单击,表单正在完美加载,但当我关闭API并再次单击按钮加载时,它会抛出一个异常,说明:

The process cannot access the file 'D:\MIT\project\wordnet API\TestApplication\WNdb-3.0\dict\index.adj' because it is being used by another process.
以下代码正在引发异常:

BinarySearchTextStream searchStream = new BinarySearchTextStream(indexPath, new BinarySearchTextStream.SearchComparisonDelegate(delegate(string searchWord, string currentLine)
                        {
                            // if we landed on the header text, search further down
                            if (currentLine[0] == ' ')
                                return 1;

                            string currentWord = currentLine.Substring(0, currentLine.IndexOf(' '));
                            return searchWord.CompareTo(currentWord);

                        }));

请帮忙

这个问题无法用你在这里介绍的内容来回答。没有人知道什么是“BinarySearchTextStream”以及它的功能(至少谷歌没有提到它)。我只能给你一些一般性的建议-关闭你的流,使用(…){},不要打开带有独占标志的文件(例如FileShare.None)。

这个问题不能用你在这里介绍的内容来回答。没有人知道什么是“BinarySearchTextStream”以及它的功能(至少谷歌没有提到它)。我只能给你一些一般性的建议-关闭你的流,使用using(…){},不要打开带有独占标志的文件(例如FileShare.None)。

试着在你定义searchStream时抛出using()块。看起来您正在使用一个单词词典库,它可能需要对词典文件使用独占锁。看看是否有允许多次读取的选项,或者确保您正确地处理资源(这将释放所有锁)。请给我一些使用语句的示例,然后我可以检查我的一个。。。thanx for ur kind helpusing(BinarySearchTextStream searchStream=new…{}尝试在定义searchStream时抛出一个using()块。看起来您正在使用一个单词词典库,它可能需要对词典文件使用独占锁。看看是否有允许多次读取的选项,或者确保您正确地处理资源(这将释放所有锁)。请给我一些使用语句的示例,然后我可以检查我的一个。。。thanx for ur kind helpusing(BinarySearchTextStream searchStream=new…{}hi thanx for help这是BinarySearchTextStream公共类BinarySearchTextStream的代码:SearchTextStream{public BinarySearchTextStream(Stream,BinarySearchTextStream.SearchComparisonEndelegate searchComparison);public BinarySearchTextStream(字符串路径,BinarySearchTextStream.SearchComparisonEndElegate searchComparison);public override字符串搜索(字符串键,长起始,长结束);public delegate int SearchComparisonEndElegate(字符串键,字符串当前行);}请帮助这不是代码,但是从元数据生成的方法签名——这不会改变任何事情。您是否尝试关闭此BinarySearchTextStream或对其使用using语句?是的,我需要帮助。。我很早就试过了。。之后我上传了问题:(请给我一些使用语句的例子,然后我可以用我的一个…thanx查看你的帮助看这里流是如何使用的:hi thanx查看帮助这是BinarySearchTextStream的代码公共类BinarySearchTextStream:SearchTextStream{public BinarySearchTextStream{public BinarySearchTextStream}(Stream Stream,BinarySearchTextStream.SearchComparisonDelegate searchComparison);public BinarySearchTextStream(字符串路径,BinarySearchTextStream.SearchComparisonDelegate searchComparison);public override string Search(字符串键,长起点,长终点);public delegate int SearchComparisonEndegate(string key,string currentLine);}请帮助thanX这不是代码,而是从元数据生成的方法签名-这不会改变任何东西。您是否尝试关闭此BinarySearchTextStream或使用using语句?是的,我需要帮助..我很早就尝试了..之后我上传了问题:(请给我一些使用语句的例子,然后我可以用我的一个…thanx查看这里如何使用流: