c# - Return HttpResponseMessage before action without disposing Service -


i new async programming , not 100% understand implementations. hence couldn't find solution problem think quite simple.

i need return httpresponsemessage before run expensive tasks. problem is, if run program shown in code below, return new httpresponsemessage(httpstatuscode.ok); executed after getasynccompanysettingsbygroup.

so how can first return httpresponsemessage , execute async task?

public class eventcontroller : apicontroller {     public readonly  icompanyapisettingsservice compapiservice;     public eventcontroller(icompanyapisettingsservice _compapiservice)     {         compapiservice = _compapiservice;     }      public async task<httpresponsemessage> post([frombody]jobject tlaction, int group)     {         var tlaction = tlaction.toobject<teamleaderaction>();         tlaction.api_group = group;          //return badrequest if values missing        if(group == null ||  string.isnullorempty(tlaction.object_type) || string.isnullorempty(tlaction.event_type))          return new httpresponsemessage(httpstatuscode.badrequest);              await task.run(() => compapiservice.getasynccompanysettingsbygroup(tlaction.api_group));              return new httpresponsemessage(httpstatuscode.ok);       }   } 

initialy didn't use async post, , await. worked compapiservice disposed.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -