title: C# Silverlight - Delay Child Window Load?
body: <h3>The Scenario</h3>
  
  <p>Currently I have a C# Silverlight Application That uses the domainservice class and the ADO.Net Entity Framework to communicate with my database. I want to load a child window upon clicking a button with some data that I retrieve from a server-side query to the database.</p>
  
  <h3>The Process</h3>
  
  <p>The first part of this process involves two load operations to load separate data from 2 tables. The next part of the process involves combining those lists of data to display in a listbox.</p>
  
  <h3>The Problem</h3>
  
  <p>The problem with this is that the first two asynchronous load operations haven't returned the data by the time the section of code to combine these lists of data is reached, thus result in a null value exception.....</p>
  
  <h3>Initial Load Operations To Get The Data:</h3>
  
  <pre><code>public void LoadAudits(Guid jobID)
          {
              var context = new InmZenDomainContext();
  
              var imageLoadOperation = context.Load(context.GetImageByIDQuery(jobID));
              imageLoadOperation.Completed += (sender3, e3) =&gt;
              {
                  imageList = ((LoadOperation&lt;InmZen.Web.Image&gt;)sender3).Entities.ToList();
              };
  
              var auditLoadOperation = context.Load(context.GetAuditByJobIDQuery(jobID));
              auditLoadOperation.Completed += (sender2, e2) =&gt;
              {
                  auditList = ((LoadOperation&lt;Audit&gt;)sender2).Entities.ToList();
              };
          }
  </code></pre>
  
  <h3>I Then Want To Execute This Immediately:</h3>
  
  <pre><code>IEnumerable&lt;JobImageAudit&gt; jobImageAuditList
                  = from a in auditList
                    join ai in imageList
                    on a.ImageID equals ai.ImageID
                    select new JobImageAudit
                    {
                        JobID = a.JobID,
                        ImageID = a.ImageID.Value,
                        CreatedBy = a.CreatedBy,
                        CreatedDate = a.CreatedDate,
                        Comment = a.Comment,
                        LowResUrl = ai.LowResUrl,
  
                    };
  
              auditTrailList.ItemsSource = jobImageAuditList;
  </code></pre>
  
  <h3>However I can't because the async calls haven't returned with the data yet...</h3>
  
  <h3>Thus I have to do this (Perform the Load Operations, Then Press A Button On The Child Window To Execute The List Concatenation and binding):</h3>
  
  <pre><code>private void LoadAuditsButton_Click(object sender, RoutedEventArgs e)
          {
  
              IEnumerable&lt;JobImageAudit&gt; jobImageAuditList
                  = from a in auditList
                    join ai in imageList
                    on a.ImageID equals ai.ImageID
                    select new JobImageAudit
                    {
                        JobID = a.JobID,
                        ImageID = a.ImageID.Value,
                        CreatedBy = a.CreatedBy,
                        CreatedDate = a.CreatedDate,
                        Comment = a.Comment,
                        LowResUrl = ai.LowResUrl,
  
                    };
  
              auditTrailList.ItemsSource = jobImageAuditList;
          }
  </code></pre>
  
  <h3>Potential Ideas for Solutions:</h3>
  
  <p>Delay the child window displaying somehow?
  Potentially use DomainDataSource and the Activity Load control?!</p>
  
  <p>Any thoughts, help, solutions, samples comments etc. greatly appreciated.</p>