Currently i am storing some data in my data base and below code is job scheduler which took data and calling the webservices and it will return success or failure and i will update the coulumn in my local database. for this i need to update bulk updation with threading but it was not updating the table .
My requirement is need to call the service and return to update my db wit 500 record pre sec.
please help.
What I have tried:
for (int i = 0; i < 60; i++)
{
var value2 = await Task.Run(() => We.selectpromotiondetailsAsync(Start_Date, End_Date, 0));
Dataloopingmethod(value2, 0);
Thread.Sleep(200);
}
private async void Dataloopingmethod(WebDB.EmailPromotion[] value1, int Attemptcount)
{
try
{
foreach (var item in value1)
{
PPTSCardNumber = item.ppts_id.ToString();
if (item.couponcode == null || item.couponcode == "")
{
PIN_Req.program_id = item.promocode.ToString();
PIN_Req.ppts = PPTSCardNumber;
PIN_Req.pin = item.couponcode;
PIN_Req.promotionType = promotionType;
var response = await Task.Run(() => stp.Emailpromotion_PROC_WITHOUT_PIN_COUPONAsync(PIN_Req));
updatepromodetails(response, PPTSCardNumber, Attemptcount);
}
else
{
Coupoun_Req.program_id = item.promocode.ToString();
Coupoun_Req.ppts = PPTSCardNumber;
Coupoun_Req.pin = item.couponcode;
Coupoun_Req.promotionType = promotionType;
var response = await Task.Run(() => stp.Emailpromotion_PROC_PIN_WITH_COUPONAsync(Coupoun_Req));
updatepromodetails(response, PPTSCardNumber, Attemptcount);
}
}
}
catch (Exception ex)
{
SendEmail(ex.Message.ToString());
}
}
private async void updatepromodetails(Emailpromotion_PROC_PIN_WITH_COUPONResponse response, string petroPointsCardNumber, int Attemptcount)
{
int Update_response;
if (response.Emailpromotion_PROC_PIN_WITH_COUPONResult.IsSuccess == false)
{
Update_response = await Task.Run(() => We.updatepromotiondetailsAsync(petroPointsCardNumber, 0, Convert.ToInt32(response.Emailpromotion_PROC_PIN_WITH_COUPONResult.ResCode), response.Emailpromotion_PROC_PIN_WITH_COUPONResult.ResDescription));
ErrorCount = ErrorCount + 1;
}
else
{
Update_response = await Task.Run(() => We.updatepromotiondetailsAsync(petroPointsCardNumber, 1, Convert.ToInt32(response.Emailpromotion_PROC_PIN_WITH_COUPONResult.ResCode), response.Emailpromotion_PROC_PIN_WITH_COUPONResult.ResDescription));
ErrorCount = 0;
}
if (ErrorCount == Email_mail_Count)
{
string Message = "We are receiving total emai promotion error count from OPE for Attempt Count :" + Attemptcount + " and error was :" + ErrorCount + "- " + MachineName;
SendEmail(Message);
ErrorCount = 0;
}
}