Print Page | Close Window

Question abour results from coroutine

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=2348
Printed Date: 03-Jul-2026 at 9:16am


Topic: Question abour results from coroutine
Posted By: BillG
Subject: Question abour results from coroutine
Date Posted: 04-Dec-2010 at 10:56pm
I created my coroutine and my iterator. I have my yield returns after every asynchronous query and I have my yield return corroutine at the end of the iterator method.
 
Here is my problem. When the args.CompletedSuccessfully is reached there are 25 rows of the entity type I am returning. Here is my code. When the ResetStepTypesList is reached the variable is null. what am I doing wrong in the parameter to ResetStepTypesList method?
 

public void GetAvailableSteps()

{

var steps = Coroutine.Start(() => AvailableStepsSelector.RetrieveAvailableSteps(currentEvent));

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

if (args.CompletedSuccessfully){

ResetStepTypesList(steps.Result as IEnumerable<EventStepType>);            //Results = 25 rows 

}

else{

}

};

}

public void ResetStepTypesList(IEnumerable<EventStepType> stepTypes) steps == null at this point

{

StepTypes.Clear();

stepTypes.ForEach(StepTypes.Add);

OnPropertyChanged("StepTypes");

}




Replies:
Posted By: kimj
Date Posted: 06-Dec-2010 at 10:44am
I'll have to guess here, since I can't reproduce the problem, but it's likely an issue with the cast in the call to ResetStepTypesList.  If the result isn't truly an IEnumerable<EventStepType> the as operator will return a null, and that null would be passed to the function. 


Posted By: BillG
Date Posted: 06-Dec-2010 at 11:17am
If I set a breakpoint at the call to ResetEventTyepsList method call I can see a 25 for the number in Reulsts. So If I cast steps.Result to ObservableCollection<EventStepType> does tat access the Results value?


Posted By: kimj
Date Posted: 06-Dec-2010 at 11:22am
Try a steps.Result.GetType() to see the actual type in the IEnumerable.  You could also try the cast before calling the method and test it explicitly:
 
var myResult = steps.Result as IEnumerable<EventStepType>;
if (myResult == null) { ...casting issue }



Posted By: BillG
Date Posted: 06-Dec-2010 at 2:47pm
Strange. When I check the following line.
 

var Results = steps.Result as ObservableCollection<EventStepType>;

Steps.results = 25 and they are of type EventStepType

but Results = null after the line is executed.



Posted By: BillG
Date Posted: 07-Dec-2010 at 7:42am
When the Coroutine.Return occurs, the data type is
 
System.Collections.ObjectModel.ReadOnlyCollecton <EventStepType>   Results count = 26
 
in my Args.CompletedSuccessfully code, I do a GetType() and the data type is
 
IdeaBlade.EntityModel.EntityQueryOperations <EventStepType>
 
so what do I need to cast it to in order to get it into my ObservableCollection
 
var results = steps.Result as ?????????????????
 
ResetStepTypesList(results)
 
 
public ResetStepTypeList(<EventStepType> stepsTypes)
{
       this.StepTypes.Clear();
       stepTypes.foreach(StepTypes.Add);
}
 



Print Page | Close Window