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
if on framework 4.5 can use iregisteredobject implementation suggested in post
Comments
Post a Comment