tags:

views:

30

answers:

2

Our application downloads a large amount of data on the startup. It needs most of the data for all operations. Here is a problem: some operations can be performed only after data is loaded. As it loads asynchronously, most of user actions throw an exception.
I tried AutoResetEvent.WaitOne(), but it doesn't work correctly.

What can be done to avoid it? Thanks in advance.

A: 

Expose your data via a service, and also expose an indicator of whether the data is loading, loaded, couldn't be loaded etc. Your UI can then use this indicator to determine the availability of user interface elements (usually via commands).

You certainly should not be blocking your UI until the data loads - that defeats the whole purpose of you being forced to do it asynchronously in the first place. Instead, your UI should react according to the availability of the data as and when it loads.

HTH,
Kent

Kent Boogaart
A: 

This isn't a Silverlight problem, it's a universal producer/consumer problem.

Depending upon the exact environment andparticulars of your application, there are different approaches to it. If the data production is something that will happen VERY quickly and you only need to consume 1 unit of the specific data type, then in your consumer, you can poll a flag that you change once the data is produced. Or, you can provide the producer with a function/method to call once the data is populated. In this manner, you would push the data to the module that only displays what is available.

More complicated examples will involve queueing and signaling, but this should get you started.

San Jacinto