entity-frameworkasynchronousbackgroundworkersavechangesobjectcontext

Asynchronous ObjectContext.SaveChanges()?


I want the SaveChanges of the ObjectContext (Win apps) to save changes asynchronously, will show a marquee (or controllable?) progress bar (this I can easily implement) for the user while he is able to continue working.

I basically want to override the SaveChanges of the ObjectContext.

Has anyone thought about this before?


Solution

  • Warning: The answer below is old and may not apply to the most recent versions of the framework in question.

    I believe you need to use Asynchronous Delegates. It basically works like that:

    1. You create a delegate from the method you want to call asynchronously;

    2. You call BeginInvoke on the delegate, starting a call;

    3. You do whatever else you need to do (e.g. animate a marquee);

    4. You can either wait for the async call to finish, or check whether is has completed and keep animating the marquee if it isn't;