In my service layer I wanted to fire multiple methods asynchronously and await for their results.
I tried with one at a time and it is erroring out.
In my service class I called the method like
var _validChapterCodesTask = gd.validateChapterCodeDetails(_input1); await Task.WhenAll(_validChapterCodesTask); var _chapterCodeResult = await _validChapterCodesTask; And in DAL class the method definition looks like
public async Task<IEnumerable<ChapterCodeValidationOutput>> validateChapterCodeDetails(GroupMembershipValidationInput gmvi) { Repository rep = new Repository(); if (!gmvi._chapterCodes.All(x => x.Equals(""))) { var _validChapterCodes = await rep.ExecuteStoredProcedureAsync<Entities.Upload.ChapterCodeValidationOutput>(SQL.Upload.UploadValidation.getChapterCodeValidationSQL(gmvi._chapterCodes),null); return _validChapterCodes; } else return new List<ChapterCodeValidationOutput>(); } Error message
Error 208 The
awaitoperator can only be used within anasyncmethod. Consider marking this method with theasyncmodifier and changing its return type toTask<ARC.Donor.Business.Upload.GroupMembershipValidationOutput>.C:\Users\m1034699\Desktop\Stuart_Upgrade_2.1_New Approach\Stuart_Export_Upload_v2.1\Stuart Web Service\ARC.Donor.Service\Upload\UploadValidationServices.cs 34 13 ARC.Donor.Service
in lines
await Task.WhenAll(_validChapterCodesTask); var _chapterCodeResult = await _validChapterCodesTask; What am I doing wrong ?