Print Page | Close Window

Pausing the UI

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2337
Printed Date: 13-Mar-2025 at 12:22am


Topic: Pausing the UI
Posted By: BillG
Subject: Pausing the UI
Date Posted: 26-Nov-2010 at 12:57am
While asynchronous queries are essential to prevent the UI from hanging up while waiting for the data, sometimes it is essential that the data is retrieved before the UI is displayed. I am creating an object and then passing that object to a dialog box, unfortunately there is some processing being done on the object before it can be passed to the dialog box. The object is not being fully created before the dialog box is displayed which causes the program to crash.
 
How can I pause the app and keep the dialog box from appearing until my object is created and populated with some default values?
 
Here is what is happening? the user clicks on an add button and the object is created, the next available reference # is retrieved from the database, updated by 1 and then saved back to the database. The number is assigned to a field in the newly created object and returned back to the calling method. The calling method calls the dialog box and passes the newly created object to the viewmodel of the dialog box.
 
Here is my code from the viewmodel that is calling the create object and popping up the dialog and the repository method
 
public JobHistory newJob;

private void AddJob(object parameter){

     CreateJobHistory(CurrentMember);

     I want to put a pause here until the newJob variable is not null and a valid object.
 
     this.IsInEditing = true;

     JobHistoryEditor.Open(newJob,

     () => { // Ok callback

        this.Jobs.Add(SelectedJob);

        this.SelectedJob = newJob;

        CloseEditSession();

     },

     CloseEditSession); // Cancel

}

public void CreateJobHistory(Member member)

{

     var coop = Coroutine.Start(() => JHRepository.CreateJobHistory(member));

     coop.Completed += (sender, args) => {

     if (args.CompletedSuccessfully){

          newJob = coop.Result as JobHistory;

    }

    else{

   }

   };

}

Here is my repository method

//Coroutine Iterator

public IEnumerable<INotifyCompleted> CreateJobHistory(Member member)

{

     var localInfoOp = Manager.LocalInfos.ExecuteAsync();

     yield return localInfoOp;

//Get first LocalInfo.NextJobHistRef and increment by 1

    LocalInfo localInfos = localInfoOp.Results.First<LocalInfo>();

    int nextRefNo = localInfos.NextJobHistRef;

    localInfos.NextJobHistRef = nextRefNo + 1;

    List<Entity> changedEntities = new List<Entity>();

    changedEntities.Add(localInfos);

    var saveOp = Manager.SaveChangesAsync(changedEntities);

    saveOp.Completed += (sender, args) =>{

    if (args.CompletedSuccessfully){

    }

    else

   {

   }

   };

// ////Create a new JobHistory

   JobHistory newJob = new JobHistory{

       SocSecNo = member.SocSecNo,

       RefNo = nextRefNo,

       Member = member

   };

   yield return Coroutine.Return(newJob);

}




Replies:
Posted By: smi-mark
Date Posted: 26-Nov-2010 at 10:09am
You might want to look into using a BusyIndicator, to show a friendly busy screen while your data is loading.

I'm not sure if you are using WPF or SL but there are controls available for both


Posted By: BillG
Date Posted: 26-Nov-2010 at 11:48am
Nope that does not work. I tried that. The problem is that the dialog box is being instantianted before the object is created. I need the object to be fully created before the dialog box is called.


Posted By: smi-mark
Date Posted: 26-Nov-2010 at 11:58am
Why don't you only open the dialog once the coroutine has finished?

BusyIndicator ON
 CreateJobHistory(CurrentMember)

public void CreateJobHistory(Member member)

{

     var coop = Coroutine.Start(() => JHRepository.CreateJobHistory(member));

     coop.Completed += (sender, args) => {

     if (args.CompletedSuccessfully){

          newJob = coop.Result as JobHistory;

//Callback here or put your code in to disable busyindicator and showdialog

    }

    else{

   }

   };

}





Print Page | Close Window