简体   繁体   English

代码无故停止执行

[英]Code stops executing for no apparent reason

This is C# Winforms. 这是C#Winforms。

I have a list of strings in this code: 我在此代码中有一个字符串列表:

List<string> WaveAndPickFields = new List<string>(new string[] { "ID", "TransactionID", "OrderNumber", "WarehouseID", "StoreOrderNumber", "OrderType", "CustomerID", "CustomerPONumber", "DepartmentCode", "LoadNumber", "ReverseLoadSequence", "BOLNumber", "MasterBOLNumber", "ProNumber", "Carrier", "CarrierSCAC", "FreightTerms", "RushOrderFlag", "OrderEntryDate", "ExpectedCarrierArrivalDate", "DatePromised", "OrderWeight", "OrderCubicVolume", "OrderCartonCounts", "ShippingShort", "PrepaidFreight", "CODAmount", "InsuranceAmount", "PIPAmount", "TotalFreightCost", "ShipToCustomerCode", "ShipToName", "ShipToAddress1", "ShipToAddress2", "ShipToAddress3", "ShipToCity", "ShipToState", "ShipToZipCode", "ShipToCountryCode", "ShipToCountryName", "BillToCustomerCode", "BillToName", "BillToAddress1", "BillToAddress2", "BillToAddress3", "BillToCity", "BillToState", "BillToZipCode", "BillToCountryCode", "BillToCountryName", "DeliveryAddressName", "DeliveryAddress1", "DeliveryAddress2", "DeliveryAddress3", "DeliveryCity", "DeliveryState", "DeliveryZipCode", "DeliveryCountryCode", "DeliveryCountryName", "DeliveryPhone", "BillFreightCustomerCode", "BillFreightAddressName", "BillFreightAddress1", "BillFreightAddress2", "BillFreightAddress3", "BillFreightCity", "BillFreightState", "BillFreightZipCode", "BillFreightCountryCode", "BillFreightCountryName", "CartonLabel", "ShipVerificationFlag", "PartialOrderFlag", "EarliestShipDate", "LatestShipDate", "EarliestDeliveryDate", "LatestDeliveryDate", "PromoCode", "Route", "Stop", "ToteFlag", "Status" });

All I want to do is loop through this code and add a bunch of fields to a datatable. 我要做的就是遍历这段代码,并将一堆字段添加到数据表中。 I am doing it in this code: 我在这段代码中做到这一点:

foreach (string field in WaveAndPickFields)
{
    dtWaveAndPicks.Columns.Add(field);
}

I have also tried: 我也尝试过:

for (int i = 0; i < WaveAndPickFields.Count; i++)
{
    DataColumn column = new DataColumn(WaveAndPickFields[i]);
    dtWaveAndPicks.Columns.Add(column);
}

For whatever reason these lines appear to execute but the entire function stops and nothing else executes without an exception error. 无论出于何种原因,这些行似乎都在执行,但整个功能停止了,并且没有异常错误,其他任何程序都没有执行。

dtWaveAndPicks.Columns.Add(field);

and: 和:

dtWaveAndPicks.Columns.Add(column);

Does anyone know why this is happening? 有人知道为什么会这样吗? The alternative that does work for me is having a line that will add a column. 对我有用的替代方法是有一行将添加一列。 The problem is, I didn't want to have 80+ lines to add the fields when I could have had a loop like this. 问题是,当我有这样的循环时,我不想有80多行来添加字段。

I would strongly suggest using windbg to determine what's going on here - if you haven't used it before it can be a bit daunting but there's quite good tutorials (particularly from Tess see here ) 我强烈建议您使用windbg来确定这里发生的事情-如果您以前没有使用过它,可能会有些令人生畏,但是这里有很好的教程(特别是Tess的文章, 请参见此处

Once you've got windbg installed get a process dump via task manager when the hang occurs Open the dump file in windbg 安装完windbg后,在挂起时通过任务管理器获取进程转储在windbg中打开转储文件

Then run .symfix c:\\sos to fix the symbol path 然后运行.symfix c:\\sos修复符号路径

Next load sos .loadby sos mscorwks 下次加载sos .loadby sos mscorwks

Finally to check for an exception on any thread run .foreach (ex {!dumpheap -type Exception -short}){.echo "********************************";!pe –nested ${ex} } 最后检查运行的任何线程上的异常.foreach (ex {!dumpheap -type Exception -short}){.echo "********************************";!pe –nested ${ex} }

Give this a try & see how you get on 试试看,看看你如何过

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM