Click here to Skip to main content
15,029,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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); //send email to indicate contionous of 10 data was failed .
               ErrorCount = 0;
           }

         //  return Update_response;
       }
Posted
Updated 1-Mar-21 1:39am
v2
Comments
Chris Copeland 1-Mar-21 10:11am
   
When you say "async method failed", what do you mean? Which part of the code is failing, do you have an exception?

You also seem to be calling updatepromodetails without using await from the for loop, which means it's going to run and the loop is going to immediate jump to the sleep line. Is that intended?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900