应用程序在每个号码3286090处停止
本文关键字:3286090处 号码 应用程序 | 更新日期: 2023-09-27 17:53:00
基本上我有一个问题,应用程序只是在循环3286090或批1735后停止。
此时,我在应用程序中有一个1894个已验证地址的列表,现在创建所有可能的组合并计算每批的距离和旅行时间。此子函数调用本地web服务,该服务需要60到180秒才能完成每个批处理,并将结果写入.csv文件。(使用现有的excel库将此写入excel文件会过度占用内存,因此不能选择。)
没有例外。无系统日志。并且,ctrl+alt+e的每个"异常中断"选项都是启用的。
if (startNumber <= batchnumber)
{
calculateRouteInfo(waypointDescArrayList, batchnumber, address);
}
代码似乎在这里失败了。当batchnumber达到1735时,将其与startNumber进行比较(在本例中,我尝试输入1734来重做上一批/1735来执行当前批并尝试在1736或更高时跳过它)
无论高于1736的数字是多少,即使我告诉应用程序将X与批编号1735进行比较,应用程序也会在该特定数字处到达终点,即使我只是告诉应用程序将其与1800这样的更高数字进行比较。就这样结束了。
我试着摆弄条件和检查内存泄漏,但事实并非如此。此外,web服务在该编号之前的任何其他批次上正常运行。手动生成该批处理并将其正常发送到web-service功能
这是完整的代码。
private static void preprocessCalculation(xLocate.AddressResponse[] foundAddressess)
{
int batchnumber = 1;
List<xRoute.WaypointDesc[]> waypointDescArrayList = new List<xRoute.WaypointDesc[]>();
foreach (var foundAddress in foundAddressess)
{// 1. foundAddresses containts 1894 foundAddress'
foreach (var address in foundAddress.wrappedResultList)
{// 2. Each foundAddress.wrappedResultlist containts (in this case) 1x address.
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
var watch = Stopwatch.StartNew();
foreach (var foundAddressDest in foundAddressess)
{// 3. Here we combine each address with every address and for each address we make up a batch of combinations that we calculate.
foreach (var addressDest in foundAddressDest.wrappedResultList)
{ // 4.
#region Add waypointDesc
var waypointDescList = new List<xRoute.WaypointDesc>();
waypointDescList.Add(new xRoute.WaypointDesc()
{
linkType = xRoute.LinkType.AUTO_LINKING,
wrappedCoords = new xRoute.Point[] {
new xRoute.Point() {
point = new xRoute.PlainPoint() {
x = address.coordinates.point.x,
y = address.coordinates.point.y
}
}
}
});
waypointDescList.Add(new xRoute.WaypointDesc()
{
linkType = xRoute.LinkType.AUTO_LINKING,
wrappedCoords = new xRoute.Point[] {
new xRoute.Point() {
point = new xRoute.PlainPoint() {
x = addressDest.coordinates.point.x,
y = addressDest.coordinates.point.y
}
}
}
});
waypointDescArrayList.Add(waypointDescList.ToArray());
#endregion
}
}
if (startNumber <= batchnumber)
{ // This calculates the data and does not fail.
calculateRouteInfo(waypointDescArrayList, batchnumber, address);
}
waypointDescArrayList.Clear();
watch.Stop();
elapsedtime += watch.Elapsed.TotalSeconds;
Console.Clear();
Console.WriteLine("Voortgang calculatie... {0}/{1} ({2}s (+{3}s))", batchnumber, totalbatches, elapsedtime, watch.Elapsed.TotalSeconds);
batchnumber++;
}
}
} // 5. When going through the 1735th iteration it skips to the end of this function.
private static void calculateRouteInfo(List<xRoute.WaypointDesc[]> finalList, int batchnumber, xLocate.ResultAddress address)
{
string startlocation = string.Format("{0}-{1}-{2}-{3}", address.country, address.postCode, address.city, address.street);
var matrixDistance = matrixTemplate.Copy();
matrixDistance.Rows.Add(startlocation);
var matrixTime = matrixTemplate.Copy();
matrixTime.Rows.Add(startlocation);
var bulkRouteInfo = xRouteClient.calculateBulkRouteInfo(finalList.ToArray(), null, null, null);
finalList.Clear();
var column = 1;
foreach (var RouteInfo in bulkRouteInfo.wrappedBulkRouteInfoResult)
{
matrixDistance.Rows[0][column] = RouteInfo.routeInfo.distance;
matrixTime.Rows[0][column] = RouteInfo.routeInfo.time;
column++;
}
writeOutputMatrix(fileName, batchnumber, matrixDistance, matrixTime);
}
private static void writeOutputMatrix(string fileName, int batchnumber, DataTable matrixDistance, DataTable matrixTime)
{
string newPath = string.Format("C:/result/{0}/", fileName);
if (!Directory.Exists(newPath))
{
var newDirectory = Directory.CreateDirectory(newPath);
Console.WriteLine("Result mappen aangemaakt.");
}
var matrixDistanceBytes = Encoding.GetEncoding("iso-8859-1").GetBytes(matrixDistance.ToCSV());
using (Stream s = File.Create(string.Format("{0}{1}-distance_{2}.csv", newPath, fileName, batchnumber), matrixDistanceBytes.Length))
{
s.Write(matrixDistanceBytes, 0, matrixDistanceBytes.Length);
Console.WriteLine(string.Format("Result {0}{1}-distance_{2}.csv is aangemaakt!", newPath, fileName, batchnumber));
}
var matrixTimeBytes = Encoding.GetEncoding("iso-8859-1").GetBytes(matrixTime.ToCSV());
using (Stream s = File.Create(string.Format("{0}{1}-time_{2}.csv", newPath, fileName, batchnumber), matrixTimeBytes.Length))
{
s.Write(matrixTimeBytes, 0, matrixTimeBytes.Length);
Console.WriteLine(string.Format("Result {0}{1}-time_{2}.csv is aangemaakt!", newPath, fileName, batchnumber));
}
}
编辑:这是我的变通办法。
private static void preprocessCalculation(xLocate.AddressResponse[] foundAddressess)
{
int batchnumber = 1;
List<xRoute.WaypointDesc[]> waypointDescArrayList = new List<xRoute.WaypointDesc[]>();
foreach (var foundAddress in foundAddressess)
{
if (startNumber < batchnumber)
{
foreach (var address in foundAddress.wrappedResultList)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
var watch = Stopwatch.StartNew();
foreach (var foundAddressDest in foundAddressess)
{
foreach (var addressDest in foundAddressDest.wrappedResultList)
{
#region Add waypointDesc
var waypointDescList = new List<xRoute.WaypointDesc>();
waypointDescList.Add(new xRoute.WaypointDesc()
{
linkType = xRoute.LinkType.AUTO_LINKING,
wrappedCoords = new xRoute.Point[] {
new xRoute.Point() {
point = new xRoute.PlainPoint() {
x = address.coordinates.point.x,
y = address.coordinates.point.y
}
}
}
});
waypointDescList.Add(new xRoute.WaypointDesc()
{
linkType = xRoute.LinkType.AUTO_LINKING,
wrappedCoords = new xRoute.Point[] {
new xRoute.Point() {
point = new xRoute.PlainPoint() {
x = addressDest.coordinates.point.x,
y = addressDest.coordinates.point.y
}
}
}
});
waypointDescArrayList.Add(waypointDescList.ToArray());
#endregion
}
}
calculateRouteInfo(waypointDescArrayList, batchnumber, address);
waypointDescArrayList.Clear();
watch.Stop();
elapsedtime += watch.Elapsed.TotalSeconds;
Console.Clear();
Console.WriteLine("Voortgang calculatie... {0}/{1} ({2}s (+{3}s))", batchnumber, totalbatches, elapsedtime, watch.Elapsed.TotalSeconds);
batchnumber++;
}
}
else
{
batchnumber++;//debug
}
}
}
我将条件移动了一个堆栈,到目前为止似乎解决了问题。但我仍然想解决这个问题,为什么它停止在每一个中期。foundAddress。wrappedResultList可以包含多个结果(在这个压力测试中它不包含)。
为了暂时解决这个问题,我已经优化了代码,以便它可以防止过多和不必要的forech -loop。
然后一直数到崩溃发生的地方,然后开始一个新的循环,继续从你离开的地方开始。
一个肮脏的工作,但它的工作,而我还不知道另一个解决方案。