使用Winforms的电子表格项目,无法复制文件错误

我正在为一个软件工程类开发一个简单的Excel项目。 这是我第一次写一个DLL,并使用INotifyPropertyChanged。 我收到这些错误:

错误13无法将“SpreadsheetEngine \ bin \ Debug \ SpreadsheetEngine.dll”复制到“bin \ Debug \ SpreadsheetEngine.dll”。 超过了10.失败的重试次数。“

错误14无法将文件“SpreadsheetEngine \ bin \ Debug \ SpreadsheetEngine.dll”复制到“bin \ Debug \ SpreadsheetEngine.dll”。 该进程无法访问文件'bin \ Debug \ SpreadsheetEngine.dll',因为它正在被另一个进程使用。“

这些错误真的让我回头,我很感激任何帮助找出他们。

这是我的DLL类:

namespace SpreadsheetEngine { public abstract class Cell : INotifyPropertyChanged { private int RowIndex; private int ColumnIndex; protected string Text; protected string Value; public event PropertyChangedEventHandler PropertyChanged; //implement property changed notification protected void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(name)); } } //Text property is a getter and setter for member variable public string CellText { get { return this.Text; } set { if (Text != value) { this.Text = value; OnPropertyChanged("Text"); } } } //Value property is a string that represents the "evaluated" value. public string CellValue { get { return Value; } } abstract internal void SetValue(string value); //cell constructor sets column and row indices public Cell(int row_index, int column_index) { RowIndex = row_index; ColumnIndex = column_index; } //getters for row and column indices public int Row { get { return RowIndex; } } public int Column { get { return Column; } } } //this class inherits from cell so that we can instantiate and set value from inside public class RealCell : Cell { //constructor calls the base class constructor public RealCell(int row_index, int column_index):base(row_index, column_index) { } //this is how we'll set the value property from the spreadsheet override internal void SetValue(string new_value) { Value = new_value; } } public class Spreadsheet { public int num_rows; public int num_columns; public RealCell[,] CellArray; public int ColumnCount() { return num_columns; } public int RowCount() { return num_rows; } //constructor with 2d array to hold cell objects public Spreadsheet(int rows, int columns) { num_rows = rows; num_columns = columns; RealCell[,] cell_array = new RealCell[num_rows, num_columns]; //give all of the cells in our spreadsheet proper row and column indices for(int row = 1; row <= num_rows; row++) { //potential off by one error here at num_columns? for(char column = 'A'; column <= 'A' + num_columns; columns++) { RealCell cell = new RealCell(row, column); cell_array[row - 1, column - 65] = cell; } } CellArray = cell_array; } public event PropertyChangedEventHandler CellPropertyChanged; //implement property changed notification //TODO: implement CellPropertyChanged event protected void OnPropertyChanged(Cell cell, string name) { PropertyChangedEventHandler handler = CellPropertyChanged; if (handler == null) { handler(cell, new PropertyChangedEventArgs(name)); } } void handler(object sender, PropertyChangedEventArgs e) { RealCell cell = sender as RealCell; string text = cell.CellText; if (text[0] != '=') { cell.SetValue(text); } else { cell.SetValue(text.Substring(1, text.Length)); OnPropertyChanged(sender as Cell, "Cell Value"); } } //function returns RealCell object public RealCell get_cell(int row_index, int column_index) { if (row_index > num_rows || column_index > num_columns) { //there is no such cell. return null. return null; } else { return CellArray[row_index - 1, column_index - 65]; } } } 

}

有一个打开的文件句柄,可以防止覆盖SpreadsheetEngine.dll。 在构build解决scheme时,不能像错误消息中所述重写该文件。 解决该问题的最简单方法是将SpreadsheetEngine.dll重命名为其他内容(例如__SpreadsheetEngine.dll)。
您还可以使用ProcessExplorer查找并closures文件句柄。

所以我想清楚是什么导致了这个问题。 当我试图运行我的代码时,我注意到我的笔记本电脑风扇疯了,我的电池寿命很糟糕。 打开我的任务pipe理器后,我发现即使closures了Visual Studio,我的程序仍在运行。 原来我在这里有一个无限循环:

 for(char column = 'A'; column <= 'A' + num_columns; columns++) { RealCell cell = new RealCell(row, column); cell_array[row - 1, column - 65] = cell; } 

我增加了列而不是列。 这是一个错字,给了我所有这些悲痛。