Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
it Returns no value
Severity Code Description Project File Line Suppression State
Warning	CS4014	Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.


What I have tried:

 /* This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...).	*/
public async void ProcessRequests(object sender, ElapsedEventArgs args)
    {
      timeDelay2.Stop();
      string ID = DateTime.Now.ToString("yyyyMMddhhmmss");

      try
      {
        if (disableService == "N")
        {
          var Requests =  GetTransactions(ID);
          if (Requests != null)
          {
            int totalRows = Requests.Count;
            if (totalRows > 0)
            {
              logger.Info(" ID : " + ID + " | New Reprocessing Session Started... ");

              Parallel.ForEach(Requests,
                row =>
                {
                  //the error is at this point
                  ReprocessFailedTopUp(ID, row);
                }
                );
              logger.Info(" ID : " + ID + " | Transactions Processed : " + totalRows.ToString("N0"));
            }
          }
        }
      }
      catch (Exception exc)
      {
        logger.Error("ID : " + ID + " | Exception Occurred in Current Session | Exception : " + exc.Message);
      }
      timeDelay2.Start();
    }
Posted
Updated 9-May-18 2:38am

1 solution

The warning means that you declared your method to be asynchronous, while the method is actually synchronous. You could make your method asynchronous like so:

public async void ProcessRequests(object sender, ElapsedEventArgs args)
{
  await Task.Run(() => {
    timeDelay2.Stop();
    string ID = DateTime.Now.ToString("yyyyMMddhhmmss");

    try {
      if (disableService == "N") {
        var Requests = GetTransactions(ID);
        if (Requests != null) {
          int totalRows = Requests.Count;
          if (totalRows > 0) {
            logger.Info(" ID : " + ID + " | New Reprocessing Session Started... ");

            Parallel.ForEach(Requests,
              row => {
              //the error is at this point
              ReprocessFailedTopUp(ID, row);
              }
              );
            logger.Info(" ID : " + ID + " | Transactions Processed : " + totalRows.ToString("N0"));
          }
        }
      }
    }
    catch (Exception exc) {
      logger.Error("ID : " + ID + " | Exception Occurred in Current Session | Exception : " + exc.Message);
    }
    timeDelay2.Start();
  });
}
 
Share this answer
 

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