C# Silverlight - Delay Child Window Load?!

Posted by Goober on Stack Overflow See other posts from Stack Overflow or by Goober
Published on 2009-09-30T11:07:18Z Indexed on 2010/04/06 3:03 UTC
Read the original article Hit count: 695

Filed under:
|
|

The Scenario

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.

The Process

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.

The Problem

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.....

Initial Load Operations To Get The Data:

public void LoadAudits(Guid jobID)
        {
            var context = new InmZenDomainContext();

            var imageLoadOperation = context.Load(context.GetImageByIDQuery(jobID));
            imageLoadOperation.Completed += (sender3, e3) =>
            {
                imageList = ((LoadOperation<InmZen.Web.Image>)sender3).Entities.ToList();
            };

            var auditLoadOperation = context.Load(context.GetAuditByJobIDQuery(jobID));
            auditLoadOperation.Completed += (sender2, e2) =>
            {
                auditList = ((LoadOperation<Audit>)sender2).Entities.ToList();
            };
        }

I Then Want To Execute This Immediately:

IEnumerable<JobImageAudit> 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;

However I can't because the async calls haven't returned with the data yet...

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):

private void LoadAuditsButton_Click(object sender, RoutedEventArgs e)
        {

            IEnumerable<JobImageAudit> 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;
        }

Potential Ideas for Solutions:

Delay the child window displaying somehow? Potentially use DomainDataSource and the Activity Load control?!

Any thoughts, help, solutions, samples comments etc. greatly appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about Silverlight