读书人

本人写了一段代码访问ahci的内存同一

发布时间: 2013-11-29 13:49:33 作者: rapoo

本人写了一段代码访问ahci的内存,同一段代码不时会报出来一下错误。很困惑,求解
本帖最后由 shmily453397 于 2013-11-27 17:28:50 编辑 An unhandled exception of type 'System.ExecutionEngineException' occurred in System.Drawing.dll
An unhandled exception of type 'System.ExecutionEngineException' occurred in mscorlib.dll

AccessViolationException was unhandled。Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

An unhandled exception of type 'System.ExecutionEngineException' occurred in System.Windows.Forms.dll


通过readAHCIInfo方法里面调用createTableData(),能得到结果(见附件)
但是界面显示一会后就会出现各种异常而导致界面崩溃。

//step2 .创建方法跟委托相匹配的方法
public void readAHCIInfo(int harddiskIndex)
{
Console.WriteLine("readAHCIInfo !!!!!!!!!!!!!!!");
if (!this.dataGridView7.IsDisposed)
{
WinIO winIo = new WinIO(harddiskIndex);

DataTable ahciData = winIo.createTableData();
this.dataGridView7.DataSource = ahciData;

}
}

private DataTable CreateTable()
{
// DataTable的名字
DataTable dt = new DataTable("AHCI");
//给DataTable定列名
DataColumn dtColumn0 = new DataColumn();
dtColumn0.ColumnName = "PortID";
dt.Columns.Add(dtColumn0);

for (int index = 0; index < list_str.Count ; index++)
{
DataColumn dtColumn = new DataColumn();
dtColumn.ColumnName = list_str[index];
dt.Columns.Add(dtColumn);
}

////往DataTable里加行
DataRow dtRow;
int number = 0;
dtRow = dt.NewRow();
dtRow["PortID"] = "PortID";
dtRow[list_str[number]] = cap.Interface_Speed_Support;

dtRow[list_str[++number]] = cap.Supports_Aggressive_Link_Power_Management;

dtRow[list_str[++number]] = cap.Supports_Staggered_SpinUp;

dtRow[list_str[++number]] = cap.Supports_Native_Command_Queuing;

dtRow[list_str[++number]] = cap2.Supports_Device_Sleep;

dtRow[list_str[++number]] = cap2.Supports_Aggressive_Device_Sleep_Management;

dtRow[list_str[++number]] = cap2.DevSleep_Entrance_from_Slumber_Only;
dt.Rows.Add(dtRow);

for (int i = 0; i < portNumber; i++)
{
int j = 0;

dtRow = dt.NewRow();


dtRow["PortID"] = "PortID" + i;

dtRow[list_str[j]] = ahciInfo[i].pxCmd.Automatic_Partial_to_Slumber_Transitions_Enabled;
dtRow[list_str[++j]] = ahciInfo[i].pxCmd.Device_is_ATAPI;
dtRow[list_str[++j]] = ahciInfo[i].pxCmd.Aggressive_Link_Power_Management_Enable;
dtRow[list_str[++j]] = ahciInfo[i].pxCmd.Aggressive_Slumber_Partial;
dtRow[list_str[++j]] = ahciInfo[i].pxCmd.Interface_Communication_Control;

dtRow[list_str[++j]] = ahciInfo[i].pxTfd.ERR;
dtRow[list_str[++j]] = ahciInfo[i].pxTfd.DRQ;
dtRow[list_str[++j]] = ahciInfo[i].pxTfd.BSY;

dtRow[list_str[++j]] = ahciInfo[i].pxSsts.Device_detection;
dtRow[list_str[++j]] = ahciInfo[i].pxSsts.Current_interface_speed;
dtRow[list_str[++j]] = ahciInfo[i].pxSsts.Interface_power_management;

dtRow[list_str[++j]] = ahciInfo[i].pxSctl.Speed_Allowed;
dtRow[list_str[++j]] = ahciInfo[i].pxSctl.Interface_Power_Management_Transitions_Allowed;

dtRow[list_str[++j]] = ahciInfo[i].pxSerr.Recovered_Data_Integrity_Error;
dtRow[list_str[++j]] = ahciInfo[i].pxSerr.Recovered_Communications_Error;
dtRow[list_str[++j]] = ahciInfo[i].pxSerr.Transient_Data_Integrity_Error;
dtRow[list_str[++j]] = ahciInfo[i].pxSerr.Persistent_Communication_or_Data_Integrity_Error;
dtRow[list_str[++j]] = ahciInfo[i].pxSerr.Protocol_Error;
dtRow[list_str[++j]] = ahciInfo[i].pxSerr.Internal_Error;

dtRow[list_str[++j]] = ahciInfo[i].pxDevslp.Aggressive_Device_Sleep_Enable;
dtRow[list_str[++j]] = ahciInfo[i].pxDevslp.Device_Sleep_Present;
dtRow[list_str[++j]] = ahciInfo[i].pxDevslp.Device_Sleep_Idle_Timeout;

dt.Rows.Add(dtRow);
}
return dt;
}

本人写了一段代码访问ahci的内存,同一段代码不时会报出来一下异常。很困惑,求解 c# exception ahci datagridview
[解决办法]
Attempted to read or write protected memory. This is often an indication that other memory is corrupt
仔细考虑这个错误提示,是不是表的数据太大了?

还有用循环处理这种问题,可能是最糟糕,为何不用OO呢?为何不用ORM呢?
如果你会使用面向对象,基本上不会遇到上面的错误.

读书人网 >C#

热点推荐