I’m working on this Silverlight 3.0 Project that is completely filled with Async Calls to a Web Service. At the Main Page it fetches some needed data in order for the application to work correctly using 3 Async Calls. Right now the application does not disable any controls while executing those calls meaning a user can interact with it without that needed data. I need to disable the whole grid and only after all 3 Async calls are finished then and only then enable the grid.
What’s the best practice for doing this.
These are my calls:
client.GetAllAsync();
client.GetAllCompleted += new EventHandler<GetAllCompletedEventArgs>(client_GetAllCompleted);
client.GetActualAsync();
client.GetActualCompleted += new EventHandler<GetActualCompletedEventArgs>(client_GetActualCompleted);
client.GetSomeAsync();
client.GetSomeCompleted += new EventHandler<GetSomeCompletedEventArgs>(client_GetSomeCompleted);
Seems lot a lot of work just to queue some user interactivity.
I typically provide an application-wide interface:
In the implementation, I’ll do this:
Of course if you have heavy multi-threading then you’ll use Interlocked on those but most of the time you’ll be invoking it from the same thread. Then, you simply do:
And then on the return, just:
If you have nested calls, no problem, this method unwinds them.