My program loops through an array of null elements, assigning each element to a new object (an instance of a class I made). The array gets quite large - about 60,000 elements in size. On occasion, this loop will work, but generally the program will crash, giving a generic microsoft error "x.exe has encountered a problem and needs to close...". I have concluded that this is not a memory
size issue, but could be a memory management issue of some sort...
Here is the Point class:
public partial class Point : System.Windows.Window
{
private string m_ID;
public double x, y, power;
public string m_time;
public Point()
{
power = 0;
}
public Point(double x, double y)
{
this.x = x; this.y = y; power = 0;
}
public Point(double x, double y, int column)
{
this.x = x; this.y = y; power = 0;
}
public Point(double x, double y, int column, string time)
{
m_time = time; this.x = x; this.y = y; power = 0;
}
public Point(double x, double y, int column, string time, double power)
{
m_time = time; this.x = x; this.y = y; this.power = power;
}
public string ID
{
get
{
return m_ID;
}
set
{
m_ID = value;
}
}
public string time
{
get
{
return m_time;
}
set
{
m_time = value;
}
}
}
And here is the function which builds the array of Point's:
public Point[] getPoints(ExcelInterface excelData)
{
int longColumn = excelData.FindColumnNumber("Longitude");
int latColumn = excelData.FindColumnNumber("Latitude");
int timeColumn = excelData.FindColumnNumber("Time");
int powerColumn = excelData.FindColumnNumber("Power_dBm");
Point[] dataPoints = new Point[excelData.rows];
string hh, mm, ss, MM, dd;
hh = string.Empty; mm = string.Empty; ss = string.Empty; MM = string.Empty; dd = string.Empty;
int hour, minute, second;
double power;
DateTime time;
double[] thresholds = getPowerThresholds(numThresholds, excelData);
string dateTime, timeString;
if (System.DateTime.Now.Month < 10)
MM = "0" + System.DateTime.Now.Month.ToString();
else MM = System.DateTime.Now.Month.ToString();
if (System.DateTime.Now.Day < 10)
dd = "0" + System.DateTime.Now.Day.ToString ();
else dd = System.DateTime.Now.Day.ToString();
string date = System.DateTime.Now.Year + "-" + MM + "-" + dd;
double lat, lon;
for (int i = 2; i < excelData.rows; i++)
{
if (i % 400 == 0)
{
}
time = new DateTime();
lat = (double)excelData.GetCellValue(i, latColumn, 1);
lon = (double)excelData.GetCellValue(i, longColumn, 1);
time = (DateTime)excelData.GetCellValue(i, timeColumn, 1);
power = (double)excelData.GetCellValue(i, powerColumn, 1);
hour = time.Hour;
if (hour < 10)
hh = "0" + hour.ToString();
else hh = hour.ToString();
minute = time.Minute;
if (minute < 10)
mm = "0" + minute.ToString();
else mm = minute.ToString();
second = time.Second;
if (second < 10)
ss = "0" + second.ToString();
else ss = second.ToString();
timeString = "T" + hh + ":" + mm + ":" + ss + "Z";
dateTime = date + timeString;
try
{
dataPoints[i - 2] = new Point(lon, lat, i, dateTime);
}
catch (Exception ex)
{
}
}
I have also tested this by simplifying the loop where the error occurrs, by using only the constructor:
for (int i = 2; i &lt; excelData.rows; i++)
{
try
{
dataPoints[i - 2] = new Point(0, 0, 0, "");
}
catch (Exception ex)
{
}
}
The program still crashed with this test scenario. I have also built a simple test program which solely creates a point array and assigns each array element to a new Point. That program worked just fine with over 1million elements...
I would really appreciate any help - Ive been wrestling with this for days!
Rich