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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -