New Posts New Posts RSS Feed: Pausing the UI
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Pausing the UI

 Post Reply Post Reply
Author
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Topic: Pausing the UI
    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{

   }

   };

}


Back to Top
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post 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);

}

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down