使用Windows窗体和调用API的WordNet在按钮单击处理C#例外:访问相同的资源两次
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);
}));
请帮忙!
尝试在您的searchStream定义周围抛出一个using()块。 它看起来像你正在使用一个单词字典库,它可能要在字典文件上的排他锁。查看是否有允许多次读取的选项,或确保您正确地处理资源(这将释放任何锁)。 // MSDN: – Alan 2010-06-20 17:43:42
可以使用的语句,然后我就可以用我一个...感谢名单检查使用(BinarySearchTextStream searchStream =新...)乌尔样的帮助 – kasunmit 2010-06-20 18:04:51
{ } HTTP请给我使用的一些例子.microsoft.com/EN-US /库/ yh598w02.aspx – Alan 2010-06-20 21:20:10