CslaDataProvider Async save

CslaDataProvider Async save

Old forum URL: forums.lhotka.net/forums/t/5633.aspx


ajj3085 posted on Monday, October 20, 2008

Hi,

I was wondering if anyone had any thoughts on making Save on the CslaDataProvider honor the IsAsynchronous flag.  I'd like to do this so I can disable / enable the control while the save is running.  The problem is that while I execute code to disable the form, you can't tell because the Save immediately blocks the UI thread, so it looks like the application has hung.

Thanks
Andy

ajj3085 replied on Monday, October 20, 2008

I'm working on doing this change myself, and I'm wondering about something.

Using BeginQuery as an example..

IsBusy is set to true, then if the operation should be Asyn, the query method queued on the a new thread.  If it's not, DoQuery is called on the same thread, and then IsBusy is set (which is after OnQueryFinished is called).

However, DoQuery will set IsBusy to false prior to calling OnQueryFinished if it detect it's not on the dispatcher thread. 

Any reason for this?  Or could IsBusy = false be moved out of the if block and the DoQuery method could have the code removed?

Edit:  Figured it out.. if it sets it after the if block, IsBusy will be false even though the query thread is still running.

RockfordLhotka replied on Monday, October 20, 2008

It may be possible to put Save on a background thread.

We looked at putting Cancel/AddNew/Remove on background threads - and that is really hard, because the object is still bound to the UI and you get nasty cross-threading issues.

Save should work as long as the AutoCloneOnUpdate option is true, because the save occurs on the clone and should be safe.

I'm open to doing this in 3.6.1 - it is a good idea (if it works).

ajj3085 replied on Monday, October 20, 2008

I think I have an implementation; I'll post back if it seems to work.

Copyright (c) Marimer LLC