我收到System.Threading.ThreadAbortException:线程被中止错误每当我在我的生产环境中部署代码时,我的开发环境一切正常。我没有在我的代码中明确使用任何线程。它是web服务代码从客户端获取json并将其发送到sql存储过程以进行进一步处理
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string SaveBulkTransactionInfo(string sInputJsonString )
{
string errorString = "";
Services objservices = new Services();
SaveBulkTransactionInfoRequest ObjSaveBulkTransactionInfoRequest = new SaveBulkTransactionInfoRequest();
DateTime RequestTime, ResponseTime;
RequestTime = DateTime.Now;
int requestCount = 0;
bool catchFlag = false;
JToken json = JToken.Parse("[]");
List<SaveBulkTransactionResponse> objResponse = new List<SaveBulkTransactionResponse>();
int batchSize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TransactionLimit"]);
List<RootObject> ObjRequest1 = new List<RootObject>();
var isBulkRequest = 0;
Int64 id = 0;
try
{
ObjRequest1 = JsonConvert.DeserializeObject<List<RootObject>>(sInputJsonString);
requestCount = ObjRequest1.Count;
if (requestCount > 1)
{
isBulkRequest = 1;
}
id = objservices.WriteLogToDatabase(sInputJsonString, ObjRequest1[0].Invoice[0].Username, "SaveBulkTransactionInfo", RequestTime, ObjRequest1[0].Invoice[0].POS_CODE, Convert.ToString(ObjRequest1[0].Invoice[0].CUSTOMER_ID), ObjRequest1[0].Invoice[0].DOCNO, ObjRequest1[0].Invoice[0].DOCNOPREFIX, appVersion, isBulkRequest, requestCount);
List<List<RootObject>> objBatch = BreakIntoChunks(ObjRequest1, batchSize);
List<RootObject> ObjRequest = objBatch[0];
try
{
List<TransactionObj> lstTransactionObj = new List<TransactionObj>();
for (int i = 0; i < ObjRequest.Count; i++)
{
TransactionObj objTransaction = new TransactionObj();
Invoice objInvoice = new Invoice();
List<Payment> lstPayment = new List<Payment>();
List<ProductInfo> lstProductInfo = new List<ProductInfo>();
List<NonDiscountCoupon> lstNonDiscountCoupon = new List<NonDiscountCoupon>();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Invoice, Invoice>();
});
IMapper mapper = config.CreateMapper();
objInvoice = mapper.Map<Invoice, Invoice>(ObjRequest[i].Invoice[0]);
/* ---------------For Payment-----------------------*/
for (int k = 0; k < ObjRequest[i].Payment.Count; k++)
{
Payment objPayment = new Payment();
var configPayment = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Payment, Payment>();
});
IMapper mapperPayment = configPayment.CreateMapper();
objPayment = mapperPayment.Map<Payment, Payment>(ObjRequest[i].Payment[k]);
lstPayment.Add(objPayment);
}
/* --------------For Product----------------------------*/
for (int j = 0; j < ObjRequest[i].Transaction[0].ProductInfo.Count; j++)
{
ProductInfo objProductInfo = new ProductInfo();
var configProductInfo = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ProductInfo, ProductInfo>();
});
IMapper mapperProductInfo = configProductInfo.CreateMapper();
objProductInfo = mapperProductInfo.Map<ProductInfo, ProductInfo>(ObjRequest[i].Transaction[0].ProductInfo[j]);
lstProductInfo.Add(objProductInfo);
}
/*------------------NonDiscountCoupon----------*/
if (ObjRequest[i].NonDiscountCoupon != null)
{
for (int l = 0; l < ObjRequest[i].NonDiscountCoupon.Count; l++)
{
NonDiscountCoupon objNonDiscountCoupon = new NonDiscountCoupon();
var configNonDiscountCoupon = new MapperConfiguration(cfg =>
{
cfg.CreateMap<NonDiscountCoupon, NonDiscountCoupon>();
});
IMapper mapperNonDiscountCoupon = configNonDiscountCoupon.CreateMapper();
objNonDiscountCoupon = mapperNonDiscountCoupon.Map<NonDiscountCoupon, NonDiscountCoupon>(ObjRequest[i].NonDiscountCoupon[l]);
lstNonDiscountCoupon.Add(objNonDiscountCoupon);
}
}
objTransaction.objInvoice = objInvoice;
objTransaction.objPayment = lstPayment;
objTransaction.ProductInfo = lstProductInfo;
objTransaction.NonDiscountCoupon = lstNonDiscountCoupon;
lstTransactionObj.Add(objTransaction);
}
ObjSaveBulkTransactionInfoRequest.lstTransactions = lstTransactionObj;
objResponse = objservices.SaveBulkTransaction(ObjSaveBulkTransactionInfoRequest);
}
catch (Exception ex)
{
errorString = ex.ToString();
}
}
catch (Exception ex)
{
errorString = ex.ToString();
}
finally
{
ResponseTime = DateTime.Now;
}
return JsonConvert.SerializeObject(JToken.Parse(strJson),Formatting.Indented);
}
根据我在下面的陈述中的假设
ObjRequest1 = JsonConvert.DeserializeObject<List<RootObject>>(sInputJsonString);
它直接转到外部catch块并提供System.Threading.ThreadAbortException:线程正在中止。我无法在我的开发环境中复制相同的错误。这个错误在生产环境中随机出现。