c# - Entity Framework SaveChanges Async -


i working on audit trail feature , using entity framework.

the current code works takes long time run.

public class mydbcontext : dbcontext {    public int savechanges() {     // changes changetracker.detectchanges()      // generate custom audit trail records      return base.savechanges();   } } 

i thinking of moving audit trail building after save changes , doing async

public int savechanges() {   // changes changetracker.detectchanges()    int ret = base.savechanges();    // call async function create audit    return ret; } 

i have tried using async-await encountered problems object has been disposed. i'm not used threading/async calls.

is there way "partial" return parent process gets desired return inorder continue process, while object still alive/not-disposed continue async task.

public int savechanges() {   // changes changetracker.detectchanges()    int ret = base.savechanges();    // partial return ret;    // continue process in generating audit trail } 

in scenario using async await may not work in cases background process outlive lifetime of parent process may face situations 1 facing.

if running framework 4.5.2 or if can upgrade best option in scenario use queuebackgroundworkitem api.below links usage

http://codingcanvas.com/using-hostingenvironment-queuebackgroundworkitem-to-run-background-tasks-in-asp-net/

http://blogs.msdn.com/b/webdev/archive/2014/06/04/queuebackgroundworkitem-to-reliably-schedule-and-run-long-background-process-in-asp-net.aspx

if on framework 4.5 can use iregisteredobject implementation suggested in post

http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx/


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -