QuoteReplyTopic: Coroutine iterator question Posted: 30-Nov-2010 at 9:36am
How do I prevent my code from returning until the object created in it is full instaniated and a valid object?
//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
I just want to make sure I understand your question. Is the object in question, the newJob? If so, does the CreateJobHistory method not return until it hits the last line, yield return Coroutine.Return(newJob); ?
It is returning before it reaches the last line and moving on with next line of code which is the display of the dialog box. So the dialog box is being displayed before the object being passed to it is full created.
I see. I believe that's because the Coroutine.Start itself is an async operation. You might want to hold on displaying the dialog box by putting the display call inside the Coroutine callback after the operation is done.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum