gpt4 book ai didi

c# - 运行循环时内存不足异常

转载 作者:太空宇宙 更新时间:2023-11-03 16:12:10 25 4
gpt4 key购买 nike

此时我很困惑,我有以下代码:

            while (dal.Read())
{

if (FiltersAppliedForThisJob(dal.GetInt(0)))
continue;
var j = 0;
if (SettingsManager.OpsMgrSettings.JobViewServiceList.IsNotNull() &&
SettingsManager.OpsMgrSettings.JobViewServiceList.Count > 0)
if (!ThisJobHasASupportedService(dal.GetInt(0)))
continue;

var newJobGridRow = AddRowToJobGridWithJobID(dal.GetInt(0),
ref j);
BoldThisJobGridRowIfItIsUpdated(newJobGridRow, dal);
var jobno = dal2.GetJobNo(dal.GetInt(0).ToString());
if (locns2view.Length > 0)
_jobgrid.Rows[newJobGridRow].Visible = locns2view.Contains(jobno.Substring(0, 2));

var col = 2;
if (j < _jobgrid.ColumnCount)
for (i = 0; i < str1.Length; i++)
{
if (str1[i].Length <= 0)
continue;

if (!dal.IsFieldNull(col))
PlaceValuesInJobGridCells(dtype, i, dal2, str1, jobno, newJobGridRow, j, dal, col);
j++;
col++;
}
if (_jobgrid[0, newJobGridRow].Value.ToString() == prevjobid)
_jobgrid.Rows[newJobGridRow].Selected = true;
}

SortJobGridColumns();
}

似乎内存不足错误来自上面的代码。但是,如果我在调用 FiltersAppliedForThisJob(dal.GetInt(0) 之前放置一个 MessageBox,我不会收到任何错误。例如下面的代码:

            while (dal.Read())
{
MessageBox.Show("Done"); // for debugging purposes

if (FiltersAppliedForThisJob(dal.GetInt(0)))
continue;
var j = 0;
if (SettingsManager.OpsMgrSettings.JobViewServiceList.IsNotNull() &&
SettingsManager.OpsMgrSettings.JobViewServiceList.Count > 0)
if (!ThisJobHasASupportedService(dal.GetInt(0)))
continue;

var newJobGridRow = AddRowToJobGridWithJobID(dal.GetInt(0),
ref j);
BoldThisJobGridRowIfItIsUpdated(newJobGridRow, dal);
var jobno = dal2.GetJobNo(dal.GetInt(0).ToString());
if (locns2view.Length > 0)
_jobgrid.Rows[newJobGridRow].Visible = locns2view.Contains(jobno.Substring(0, 2));

var col = 2;
if (j < _jobgrid.ColumnCount)
for (i = 0; i < str1.Length; i++)
{
if (str1[i].Length <= 0)
continue;

if (!dal.IsFieldNull(col))
PlaceValuesInJobGridCells(dtype, i, dal2, str1, jobno, newJobGridRow, j, dal, col);
j++;
col++;
}
if (_jobgrid[0, newJobGridRow].Value.ToString() == prevjobid)
_jobgrid.Rows[newJobGridRow].Selected = true;
}

SortJobGridColumns();
}

此外,如果我删除函数调用 FiltersAppliedForThisJob(dal.GetInt(0),我不会收到错误。

函数代码如下:

  private bool FiltersAppliedForThisJob(int p)
{
var filter_datefrom = SettingsManager.OpsMgrSettings.MainView_DateFrom;
var filter_dateto = SettingsManager.OpsMgrSettings.MainView_DateTo;
var filter_status = SettingsManager.OpsMgrSettings.MainView_JobStatus;
var jobNumTbl = dal.Get_JobNumber(p);
var jobStatus = GetJobStatus(p);
var jobdate = jobNumTbl.Date;
var jobdate_res = false;
var jobstat_res = false;
var isFiltered = false;

if (jobdate.HasValue)
{
//both have values
if (filter_datefrom.HasValue && filter_dateto.HasValue)
{
if (DateTime.Compare(jobdate.Value.Date, filter_datefrom.Value.Date) < 0 ||
DateTime.Compare(jobdate.Value.Date, filter_dateto.Value.Date) > 0)
jobdate_res = true;
}
//only datefrom has value
else if (filter_datefrom.HasValue)
{
if (DateTime.Compare(jobdate.Value.Date, filter_datefrom.Value.Date) < 0)
jobdate_res = true;
}
//only datato has value
else if (filter_dateto.HasValue)
{
if (DateTime.Compare(jobdate.Value.Date, filter_dateto.Value.Date) > 0)
jobdate_res = true;
}
}

if (jobStatus.HasValue)
{
if (!filter_status.Equals(2))
if (!filter_status.Equals(jobStatus))
jobstat_res = true;
}

if (jobdate_res || jobstat_res)
isFiltered = true;


return isFiltered;
}

不确定这些信息是否足够。如果您需要我提供更多信息,请告诉我。

最佳答案

问题解决了。该应用程序在过滤之前从数据库中提取所有信息,这是大量数据。我在加载数据之前向查询添加了额外的过滤。现在一切都很好。谢谢大家

关于c# - 运行循环时内存不足异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17092555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com