Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You've got a problem in that your calling thread has no idea if the variable has been populated by the <code>LoadData()</code> call</p> <p>In thi case you need to do something like:</p> <ul> <li>Block execution until the load completes</li> <li>Raise an event when the load completes</li> <li>Set a publicly visible field on your loader to indicate load status</li> </ul> <p>One (possible) compromise would be to return a custom object instead of an IEnumerable</p> <p>The custom object could immediately attempt to load the data and keep re-trying until success. If the result set of the custom object is read before a load has occured, block the thread until the load completes, otherwise return the result set</p> <p>In this scenario, you get a benefit if there's a delay between the Load occuring and the data being used - your program can continue on until it needs the data. Whether this i useful or not depends entirely on what you're using it for.</p> <p><strong>More information on blocking execution:</strong> It depends a little on how you become aware that the connection is back up but something like:</p> <pre><code>Public Sub LoadData(Of T)(ByVal query As ObjectQuery(Of T), ByRef result As IEnumerable(Of T)) While Not Connection.State = ConnectionState.Open Threading.Thread.Sleep(100) 'Pick a decent value for this delay based on how likely it is the connection will be available quickly End While result = 'Use the connection to get your data End Sub </code></pre> <p>Is there any reason you're doing this as a sub with ByRef parameters as opposed to a function? You're only "returning" one object so I don't quite see the benefit. Not that it would make a huge difference functionally but it would be more readable...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload