c# - Updating data base asynchronously using EF6, Inside Task.Run? Performance issue -


i have wcf server application should accept call client, update in db , return response client. response client independent in result of db update, exception in update has no effect on response. using ef6 async methods. can use task.run , inside call async method:

 public boolean init(){     //do           task.run(async () =>  await updatedbasync().configureawait(false))                   .continuewith(res => _logger.warn("cannot insert session db"),                          taskcontinuationoptions.onlyonfaulted);     //do more     return true; } 

the above assure response client immediate , not dependent in db response time. second approach not using task.run:

 public boolean init(){     //do       updatedbasync().continuewith(res => _logger.warn("cannot insert session db"),                          taskcontinuationoptions.onlyonfaulted);     //do more     return true; } 

the first approach allocate thread pool thread while second run on current thread. main goal response client fast possible , question first approach (using task.run) faster or creation of thread pool thread decrease overall performance of application making response slower. note: in second approach using continuewith() , not await because want more things , return response

edit

the updatedbasync method:

    public async task updatedbasync()     {         using (var context = sqlconnectionprovider.getsqldbentitycontext())         {             try             {                 await _retrypolicy.executeasync(() => context.savechangesasync());             }             catch (dbupdateexception ex)             {             }          }     }  

both functionally identical, 1 needs take time scheduled thread pool thread before can work, yes, slower. may not huge amount slower, it'll slower.

the real possible exception if updatedbasync not actually asynchronous, , in fact bunch of work synchronously despite name. long name not lie, there's no reason use task.run here.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -