New Posts New Posts RSS Feed: Coroutine iterator question
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Coroutine iterator question

 Post Reply Post Reply
Author
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 Topic: 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

{

SocSecNo = member.SocSecNo,

RefNo = nextRefNo,

Member = member

};

yield return Coroutine.Return(newJob);

}

Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 01-Dec-2010 at 11:03am
Hi BillG;

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); ?
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: 01-Dec-2010 at 11:12am
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.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 01-Dec-2010 at 11:16am
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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down